mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #759 from ynput/feature/AY-2480_tokens-unify-the-logic-of-anatomy-and-subset-profiles
Product name: Support task short name
This commit is contained in:
commit
6cc513281b
6 changed files with 80 additions and 9 deletions
|
|
@ -13,6 +13,7 @@ import pyblish.api
|
|||
import ayon_api
|
||||
|
||||
from ayon_core.settings import get_project_settings
|
||||
from ayon_core.lib import is_func_signature_supported
|
||||
from ayon_core.lib.attribute_definitions import (
|
||||
UnknownDef,
|
||||
serialize_attr_defs,
|
||||
|
|
@ -1404,6 +1405,7 @@ class CreateContext:
|
|||
self._current_workfile_path = None
|
||||
self._current_project_settings = None
|
||||
|
||||
self._current_project_entity = _NOT_SET
|
||||
self._current_folder_entity = _NOT_SET
|
||||
self._current_task_entity = _NOT_SET
|
||||
self._current_task_type = _NOT_SET
|
||||
|
|
@ -1592,6 +1594,22 @@ class CreateContext:
|
|||
self._current_task_type = task_type
|
||||
return self._current_task_type
|
||||
|
||||
def get_current_project_entity(self):
|
||||
"""Project entity for current context project.
|
||||
|
||||
Returns:
|
||||
Union[dict[str, Any], None]: Folder entity.
|
||||
|
||||
"""
|
||||
if self._current_project_entity is not _NOT_SET:
|
||||
return copy.deepcopy(self._current_project_entity)
|
||||
project_entity = None
|
||||
project_name = self.get_current_project_name()
|
||||
if project_name:
|
||||
project_entity = ayon_api.get_project(project_name)
|
||||
self._current_project_entity = project_entity
|
||||
return copy.deepcopy(self._current_project_entity)
|
||||
|
||||
def get_current_folder_entity(self):
|
||||
"""Folder entity for current context folder.
|
||||
|
||||
|
|
@ -1788,6 +1806,7 @@ class CreateContext:
|
|||
self._current_task_name = task_name
|
||||
self._current_workfile_path = workfile_path
|
||||
|
||||
self._current_project_entity = _NOT_SET
|
||||
self._current_folder_entity = _NOT_SET
|
||||
self._current_task_entity = _NOT_SET
|
||||
self._current_task_type = _NOT_SET
|
||||
|
|
@ -2083,13 +2102,22 @@ class CreateContext:
|
|||
# TODO validate types
|
||||
_pre_create_data.update(pre_create_data)
|
||||
|
||||
product_name = creator.get_product_name(
|
||||
project_entity = self.get_current_project_entity()
|
||||
args = (
|
||||
project_name,
|
||||
folder_entity,
|
||||
task_entity,
|
||||
variant,
|
||||
self.host_name,
|
||||
)
|
||||
kwargs = {"project_entity": project_entity}
|
||||
# Backwards compatibility for 'project_entity' argument
|
||||
# - 'get_product_name' signature changed 24/07/08
|
||||
if not is_func_signature_supported(
|
||||
creator.get_product_name, *args, **kwargs
|
||||
):
|
||||
kwargs.pop("project_entity")
|
||||
product_name = creator.get_product_name(*args, **kwargs)
|
||||
|
||||
instance_data = {
|
||||
"folderPath": folder_entity["path"],
|
||||
|
|
|
|||
|
|
@ -297,7 +297,6 @@ class BaseCreator:
|
|||
))
|
||||
setattr(self, key, value)
|
||||
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
"""Identifier of creator (must be unique).
|
||||
|
|
@ -493,7 +492,8 @@ class BaseCreator:
|
|||
task_entity,
|
||||
variant,
|
||||
host_name=None,
|
||||
instance=None
|
||||
instance=None,
|
||||
project_entity=None,
|
||||
):
|
||||
"""Return product name for passed context.
|
||||
|
||||
|
|
@ -510,8 +510,9 @@ class BaseCreator:
|
|||
instance (Optional[CreatedInstance]): Object of 'CreatedInstance'
|
||||
for which is product name updated. Passed only on product name
|
||||
update.
|
||||
"""
|
||||
project_entity (Optional[dict[str, Any]]): Project entity.
|
||||
|
||||
"""
|
||||
if host_name is None:
|
||||
host_name = self.create_context.host_name
|
||||
|
||||
|
|
@ -537,7 +538,8 @@ class BaseCreator:
|
|||
self.product_type,
|
||||
variant,
|
||||
dynamic_data=dynamic_data,
|
||||
project_settings=self.project_settings
|
||||
project_settings=self.project_settings,
|
||||
project_entity=project_entity,
|
||||
)
|
||||
|
||||
def get_instance_attr_defs(self):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import ayon_api
|
||||
|
||||
from ayon_core.settings import get_project_settings
|
||||
from ayon_core.lib import filter_profiles, prepare_template_data
|
||||
|
||||
|
|
@ -88,6 +90,7 @@ def get_product_name(
|
|||
dynamic_data=None,
|
||||
project_settings=None,
|
||||
product_type_filter=None,
|
||||
project_entity=None,
|
||||
):
|
||||
"""Calculate product name based on passed context and AYON settings.
|
||||
|
||||
|
|
@ -120,12 +123,18 @@ def get_product_name(
|
|||
product_type_filter (Optional[str]): Use different product type for
|
||||
product template filtering. Value of `product_type` is used when
|
||||
not passed.
|
||||
project_entity (Optional[Dict[str, Any]]): Project entity used when
|
||||
task short name is required by template.
|
||||
|
||||
Returns:
|
||||
str: Product name.
|
||||
|
||||
Raises:
|
||||
TaskNotSetError: If template requires task which is not provided.
|
||||
TemplateFillError: If filled template contains placeholder key which
|
||||
is not collected.
|
||||
"""
|
||||
|
||||
"""
|
||||
if not product_type:
|
||||
return ""
|
||||
|
||||
|
|
@ -150,6 +159,16 @@ def get_product_name(
|
|||
if "{task}" in template.lower():
|
||||
task_value = task_name
|
||||
|
||||
elif "{task[short]}" in template.lower():
|
||||
if project_entity is None:
|
||||
project_entity = ayon_api.get_project(project_name)
|
||||
task_types_by_name = {
|
||||
task["name"]: task for task in
|
||||
project_entity["taskTypes"]
|
||||
}
|
||||
task_short = task_types_by_name.get(task_type, {}).get("shortName")
|
||||
task_value["short"] = task_short
|
||||
|
||||
fill_pairs = {
|
||||
"variant": variant,
|
||||
"family": product_type,
|
||||
|
|
|
|||
|
|
@ -166,6 +166,12 @@ class AbstractPublisherBackend(AbstractPublisherCommon):
|
|||
) -> Union[TaskItem, None]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_project_entity(
|
||||
self, project_name: str
|
||||
) -> Union[Dict[str, Any], None]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_folder_entity(
|
||||
self, project_name: str, folder_id: str
|
||||
|
|
|
|||
|
|
@ -193,6 +193,9 @@ class PublisherController(
|
|||
def get_convertor_items(self):
|
||||
return self._create_model.get_convertor_items()
|
||||
|
||||
def get_project_entity(self, project_name):
|
||||
return self._projects_model.get_project_entity(project_name)
|
||||
|
||||
def get_folder_type_items(self, project_name, sender=None):
|
||||
return self._projects_model.get_folder_type_items(
|
||||
project_name, sender
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from ayon_core.lib.attribute_definitions import (
|
|||
)
|
||||
from ayon_core.lib.profiles_filtering import filter_profiles
|
||||
from ayon_core.lib.attribute_definitions import UIDef
|
||||
from ayon_core.lib import is_func_signature_supported
|
||||
from ayon_core.pipeline.create import (
|
||||
BaseCreator,
|
||||
AutoCreator,
|
||||
|
|
@ -26,6 +27,7 @@ from ayon_core.tools.publisher.abstract import (
|
|||
AbstractPublisherBackend,
|
||||
CardMessageTypes,
|
||||
)
|
||||
|
||||
CREATE_EVENT_SOURCE = "publisher.create.model"
|
||||
|
||||
|
||||
|
|
@ -356,13 +358,24 @@ class CreateModel:
|
|||
project_name, task_item.task_id
|
||||
)
|
||||
|
||||
return creator.get_product_name(
|
||||
project_entity = self._controller.get_project_entity(project_name)
|
||||
args = (
|
||||
project_name,
|
||||
folder_entity,
|
||||
task_entity,
|
||||
variant,
|
||||
instance=instance
|
||||
variant
|
||||
)
|
||||
kwargs = {
|
||||
"instance": instance,
|
||||
"project_entity": project_entity,
|
||||
}
|
||||
# Backwards compatibility for 'project_entity' argument
|
||||
# - 'get_product_name' signature changed 24/07/08
|
||||
if not is_func_signature_supported(
|
||||
creator.get_product_name, *args, **kwargs
|
||||
):
|
||||
kwargs.pop("project_entity")
|
||||
return creator.get_product_name(*args, **kwargs)
|
||||
|
||||
def create(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue