Skip to content

Commit

Permalink
Fixed full path for directories and type_tables when get by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed May 28, 2024
1 parent 2543c9c commit 65ba221
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions python/ccdb/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,21 @@ def create_directory(self, new_dir_name, parent_dir_or_path, comment=""):
return directory

def get_directory_by_id(self, dir_id):
return self.session.query(Directory).filter(Directory.id == dir_id).one()
self._ensure_dirs_loaded()
return self.dirs_by_id[dir_id]

def get_type_table_by_id(self, table_id):
return self.session.query(TypeTable).filter(TypeTable.id == table_id).one()
type_table = self.session.query(TypeTable).filter(TypeTable.id == table_id).one()
assert isinstance(type_table, TypeTable)

# We set parent_dir here manually because we want to ensure that
# the directory comes after self._ensure_dirs_loaded() is called
# this is important to have all directories correct full paths to be set
# and consequently to have correct full path set for the table!!!!!!
parent_dir = self.get_directory_by_id(type_table.parent_dir_id)
type_table.parent_dir = parent_dir

return parent_dir

# @brief Updates directory
#
Expand Down
2 changes: 2 additions & 0 deletions python/ccdb/webgui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def directory_tree():
@app.route('/get-dir-info/<int:dir_id>')
def get_dir_info(dir_id):
db: ccdb.AlchemyProvider = g.db
db._ensure_dirs_loaded()
directory = db.get_directory_by_id(dir_id)
if not directory:
return jsonify({"error": "Directory not found"}), 404
Expand All @@ -122,6 +123,7 @@ def get_dir_info(dir_id):
@app.route('/get-table-info/<int:table_id>')
def get_table_info(table_id):
db: ccdb.AlchemyProvider = g.db
db._ensure_dirs_loaded()
table = db.get_type_table_by_id(table_id)
if not table:
return jsonify({"error": "Table not found"}), 404
Expand Down

0 comments on commit 65ba221

Please sign in to comment.