diff --git a/openpype/client/__init__.py b/openpype/client/__init__.py index 2ef32d6a83..2fa7730839 100644 --- a/openpype/client/__init__.py +++ b/openpype/client/__init__.py @@ -23,7 +23,7 @@ from .entities import ( get_last_version_by_subset_name, get_output_link_versions, - get_representation, + get_representation_by_id, get_representation_by_name, get_representations, get_representation_parents, @@ -58,7 +58,7 @@ __all__ = ( "get_last_version_by_subset_name", "get_output_link_versions", - "get_representation", + "get_representation_by_id", "get_representation_by_name", "get_representations", "get_representation_parents", diff --git a/openpype/client/entities.py b/openpype/client/entities.py index 232d9aebcc..7abb25e380 100644 --- a/openpype/client/entities.py +++ b/openpype/client/entities.py @@ -716,7 +716,21 @@ def get_last_version_by_subset_name( ) -def get_representation(project_name, representation_id, fields=None): +def get_representation_by_id(project_name, representation_id, fields=None): + """Representation entity data by it's id. + + Args: + project_name (str): Name of project where to look for queried entities. + representation_id (str|ObjectId): Representation id. + fields (list[str]): Fields that should be returned. All fields are + returned if 'None' is passed. + + Returns: + None: If representation with specified filters was not found. + Dict: Representation entity data which can be reduced + to specified 'fields'. + """ + if not representation_id: return None @@ -735,17 +749,32 @@ def get_representation(project_name, representation_id, fields=None): def get_representation_by_name( project_name, representation_name, version_id, fields=None ): + """Representation entity data by it's name and it's version id. + + Args: + project_name (str): Name of project where to look for queried entities. + representation_name (str): Representation name. + version_id (str|ObjectId): Id of parent version entity. + fields (list[str]): Fields that should be returned. All fields are + returned if 'None' is passed. + + Returns: + None: If representation with specified filters was not found. + Dict: Representation entity data which can be reduced + to specified 'fields'. + """ + + version_id = _convert_id(version_id) if not version_id or not representation_name: return None repre_types = ["representation", "archived_representations"] query_filter = { "type": {"$in": repre_types}, "name": representation_name, - "parent": _convert_id(version_id) + "parent": version_id } conn = _get_project_connection(project_name) - return conn.find_one(query_filter, _prepare_fields(fields)) diff --git a/openpype/tools/sceneinventory/model.py b/openpype/tools/sceneinventory/model.py index 8c49933e80..117bdfcba1 100644 --- a/openpype/tools/sceneinventory/model.py +++ b/openpype/tools/sceneinventory/model.py @@ -11,7 +11,7 @@ from openpype.client import ( get_subset_by_id, get_version_by_id, get_last_version_by_subset_id, - get_representation, + get_representation_by_id, ) from openpype.pipeline import ( legacy_io, @@ -313,8 +313,8 @@ class InventoryModel(TreeModel): for repre_id, group_dict in sorted(grouped.items()): group_items = group_dict["items"] # Get parenthood per group - representation = get_representation( - project_name, representation_id=repre_id + representation = get_representation_by_id( + project_name, repre_id ) if not representation: not_found["representation"].append(group_items) diff --git a/openpype/tools/sceneinventory/view.py b/openpype/tools/sceneinventory/view.py index d1ff91535f..8164c48a5d 100644 --- a/openpype/tools/sceneinventory/view.py +++ b/openpype/tools/sceneinventory/view.py @@ -10,7 +10,7 @@ from openpype.client import ( get_version_by_id, get_versions, get_hero_versions, - get_representation, + get_representation_by_id, get_representations, ) from openpype import style @@ -657,9 +657,9 @@ class SceneInventoryView(QtWidgets.QTreeView): project_name = legacy_io.active_project() # Get available versions for active representation - repre_doc = get_representation( + repre_doc = get_representation_by_id( project_name, - representation_id=active["representation"], + active["representation"], fields=["parent"] )