renamed 'get_representation' to 'get_representation_by_id'

This commit is contained in:
Jakub Trllo 2022-06-07 18:27:54 +02:00
parent ba6ef6d2ae
commit cde47eefa8
4 changed files with 40 additions and 11 deletions

View file

@ -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",

View file

@ -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))

View file

@ -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)

View file

@ -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"]
)