Skip to content

Entity hub: Small refactor and add product & version #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Nov 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
852a913
use explicit arguments in entity init
iLLiCiTiT Oct 21, 2024
e29f38f
delegated common attributes to base entity
iLLiCiTiT Oct 25, 2024
e43b27f
use 'fetch' over 'query'
iLLiCiTiT Oct 25, 2024
9452e37
added some typehints
iLLiCiTiT Oct 25, 2024
41ddf87
simplified ProjectEntity arguments
iLLiCiTiT Oct 25, 2024
98e9db2
better arguments order for folder entity
iLLiCiTiT Oct 25, 2024
f59f878
even better args order
iLLiCiTiT Oct 25, 2024
4679f6f
match order of args in classmethod
iLLiCiTiT Oct 25, 2024
6d7002b
better order of arguments for task entity
iLLiCiTiT Oct 25, 2024
fdc27eb
removed unused variable
iLLiCiTiT Oct 25, 2024
1984157
use folder_id instead of parent_id
iLLiCiTiT Oct 25, 2024
ad1f629
don't add attribs to data automatically
iLLiCiTiT Oct 25, 2024
71496fb
added product and version entity
iLLiCiTiT Oct 25, 2024
82c8835
implement remaining abstract properties
iLLiCiTiT Oct 25, 2024
b4fc406
added few helper functions to get entities
iLLiCiTiT Oct 25, 2024
ee1e01e
fix ownAttrib on version
iLLiCiTiT Oct 28, 2024
de8a1fb
avoid crashes for entities without thumbnail id
iLLiCiTiT Oct 28, 2024
f174b3e
fix docstring
iLLiCiTiT Oct 28, 2024
7c55604
fix typehint
iLLiCiTiT Oct 28, 2024
6b48b9c
added option to get product and version entities
iLLiCiTiT Oct 28, 2024
8a56ed6
added option to create new entities
iLLiCiTiT Oct 28, 2024
abfcb2c
updated typehint literal
iLLiCiTiT Oct 28, 2024
76b243f
Union is imported only for typehints
iLLiCiTiT Oct 28, 2024
8a52679
fix typo
iLLiCiTiT Oct 28, 2024
80bdd71
keep folder and task type as first in arguments
iLLiCiTiT Oct 28, 2024
61227c6
fix linting issues
iLLiCiTiT Oct 28, 2024
ccaa289
updated some docstrings
iLLiCiTiT Oct 28, 2024
b9ff48c
Merge branch 'develop' into enhancemet/entity-hub-update
iLLiCiTiT Nov 15, 2024
21805f6
Merge branch 'develop' into enhancemet/entity-hub-update
iLLiCiTiT Nov 19, 2024
b6ce89c
Merge branch 'develop' into enhancemet/entity-hub-update
iLLiCiTiT Nov 19, 2024
7d4647c
fix ownAttrib for product
iLLiCiTiT Nov 21, 2024
8d4d524
removed 'own_attributes' from products getter
iLLiCiTiT Nov 21, 2024
7db7949
swap arguments order
iLLiCiTiT Nov 21, 2024
f25ef18
use correct default values for created
iLLiCiTiT Nov 22, 2024
59b1e14
fix creted for product and version
iLLiCiTiT Nov 22, 2024
55bdf37
add thumbnail id to task fields
iLLiCiTiT Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added few helper functions to get entities
  • Loading branch information
iLLiCiTiT committed Oct 25, 2024
commit b4fc406adcbfab8cd4088f7b806bc2b78121f29c
69 changes: 67 additions & 2 deletions ayon_api/entity_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_folder_by_id(

Args:
entity_id (str): Folder entity id.
allow_fetch (bool): Try to query entity from server if is not
allow_fetch (bool): Try to fetch entity from server if is not
available in cache.

Returns:
Expand All @@ -191,7 +191,7 @@ def get_task_by_id(

Args:
entity_id (str): Id of task entity.
allow_fetch (bool): Try to query entity from server if is not
allow_fetch (bool): Try to fetch entity from server if is not
available in cache.

Returns:
Expand All @@ -201,6 +201,47 @@ def get_task_by_id(
if allow_fetch:
return self.get_or_fetch_entity_by_id(entity_id, ["task"])
return self._entities_by_id.get(entity_id)

def get_product_by_id(
self,
entity_id: str,
allow_fetch: Optional[bool] = True,
) -> Optional["ProductEntity"]:
"""Get product entity by id.

Args:
entity_id (str): Product id.
allow_fetch (bool): Try to fetch entity from server if is not
available in cache.

Returns:
Optional[ProductEntity]: Product entity object or None.

"""
if allow_fetch:
return self.get_or_fetch_entity_by_id(entity_id, ["product"])
return self._entities_by_id.get(entity_id)

def get_version_by_id(
self,
entity_id: str,
allow_fetch: Optional[bool] = True,
) -> Optional["VersionEntity"]:
"""Get version entity by id.

Args:
entity_id (str): Version id.
allow_fetch (bool): Try to fetch entity from server if is not
available in cache.

Returns:
Optional[VersionEntity]: Version entity object or None.

"""
if allow_fetch:
return self.get_or_fetch_entity_by_id(entity_id, ["version"])
return self._entities_by_id.get(entity_id)

def get_or_fetch_entity_by_id(
self,
entity_id: str,
Expand Down Expand Up @@ -241,6 +282,20 @@ def get_or_fetch_entity_by_id(
fields=self._get_task_fields(),
own_attributes=True
)
elif entity_type == "product":
entity_data = self._connection.get_product_by_id(
self.project_name,
entity_id,
fields=self._get_product_fields(),
own_attributes=True
)
elif entity_type == "version":
entity_data = self._connection.get_version_by_id(
self.project_name,
entity_id,
fields=self._get_version_fields(),
own_attributes=True
)
else:
raise ValueError(
"Unknonwn entity type \"{}\"".format(entity_type)
Expand Down Expand Up @@ -714,6 +769,16 @@ def _get_task_fields(self) -> Set[str]:
self._connection.get_default_fields_for_type("task")
)

def _get_product_fields(self) -> Set[str]:
return set(
self._connection.get_default_fields_for_type("product")
)

def _get_version_fields(self) -> Set[str]:
return set(
self._connection.get_default_fields_for_type("version")
)

def fetch_hierarchy_entities(self):
"""Query whole project at once."""
project_entity = self.fill_project_from_server()
Expand Down