mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
implemented logic to revert to default values
This commit is contained in:
parent
9fbc08dd5e
commit
3a8a9ec483
3 changed files with 93 additions and 34 deletions
|
|
@ -375,6 +375,14 @@ class AbstractPublisherFrontend(AbstractPublisherCommon):
|
|||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def revert_instances_create_attr_values(
|
||||
self,
|
||||
instance_ids: List["Union[str, None]"],
|
||||
key: str,
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_publish_attribute_definitions(
|
||||
self,
|
||||
|
|
@ -397,6 +405,15 @@ class AbstractPublisherFrontend(AbstractPublisherCommon):
|
|||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def revert_instances_publish_attr_values(
|
||||
self,
|
||||
instance_ids: List["Union[str, None]"],
|
||||
plugin_name: str,
|
||||
key: str,
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_product_name(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -412,6 +412,11 @@ class PublisherController(
|
|||
instance_ids, key, value
|
||||
)
|
||||
|
||||
def revert_instances_create_attr_values(self, instance_ids, key):
|
||||
self._create_model.revert_instances_create_attr_values(
|
||||
instance_ids, key
|
||||
)
|
||||
|
||||
def get_publish_attribute_definitions(self, instance_ids, include_context):
|
||||
"""Collect publish attribute definitions for passed instances.
|
||||
|
||||
|
|
@ -432,6 +437,13 @@ class PublisherController(
|
|||
instance_ids, plugin_name, key, value
|
||||
)
|
||||
|
||||
def revert_instances_publish_attr_values(
|
||||
self, instance_ids, plugin_name, key
|
||||
):
|
||||
return self._create_model.revert_instances_publish_attr_values(
|
||||
instance_ids, plugin_name, key
|
||||
)
|
||||
|
||||
def get_product_name(
|
||||
self,
|
||||
creator_identifier,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ from ayon_core.tools.publisher.abstract import (
|
|||
)
|
||||
|
||||
CREATE_EVENT_SOURCE = "publisher.create.model"
|
||||
_DEFAULT_VALUE = object()
|
||||
|
||||
|
||||
class CreatorType:
|
||||
|
|
@ -752,20 +753,12 @@ class CreateModel:
|
|||
self._remove_instances_from_context(instance_ids)
|
||||
|
||||
def set_instances_create_attr_values(self, instance_ids, key, value):
|
||||
with self._create_context.bulk_value_changes(CREATE_EVENT_SOURCE):
|
||||
for instance_id in instance_ids:
|
||||
instance = self._get_instance_by_id(instance_id)
|
||||
creator_attributes = instance["creator_attributes"]
|
||||
attr_def = creator_attributes.get_attr_def(key)
|
||||
if (
|
||||
attr_def is None
|
||||
or not attr_def.is_value_def
|
||||
or not attr_def.visible
|
||||
or not attr_def.enabled
|
||||
or not attr_def.is_value_valid(value)
|
||||
):
|
||||
continue
|
||||
creator_attributes[key] = value
|
||||
self._set_instances_create_attr_values(instance_ids, key, value)
|
||||
|
||||
def revert_instances_create_attr_values(self, instance_ids, key):
|
||||
self._set_instances_create_attr_values(
|
||||
instance_ids, key, _DEFAULT_VALUE
|
||||
)
|
||||
|
||||
def get_creator_attribute_definitions(
|
||||
self, instance_ids: List[str]
|
||||
|
|
@ -816,28 +809,18 @@ class CreateModel:
|
|||
return output
|
||||
|
||||
def set_instances_publish_attr_values(
|
||||
self, instance_ids, plugin_name, key, value
|
||||
self, instance_ids, plugin_name, key, value
|
||||
):
|
||||
with self._create_context.bulk_value_changes(CREATE_EVENT_SOURCE):
|
||||
for instance_id in instance_ids:
|
||||
if instance_id is None:
|
||||
instance = self._create_context
|
||||
else:
|
||||
instance = self._get_instance_by_id(instance_id)
|
||||
plugin_val = instance.publish_attributes[plugin_name]
|
||||
attr_def = plugin_val.get_attr_def(key)
|
||||
# Ignore if attribute is not available or enabled/visible
|
||||
# on the instance, or the value is not valid for definition
|
||||
if (
|
||||
attr_def is None
|
||||
or not attr_def.is_value_def
|
||||
or not attr_def.visible
|
||||
or not attr_def.enabled
|
||||
or not attr_def.is_value_valid(value)
|
||||
):
|
||||
continue
|
||||
self._set_instances_publish_attr_values(
|
||||
instance_ids, plugin_name, key, value
|
||||
)
|
||||
|
||||
plugin_val[key] = value
|
||||
def revert_instances_publish_attr_values(
|
||||
self, instance_ids, plugin_name, key
|
||||
):
|
||||
self._set_instances_publish_attr_values(
|
||||
instance_ids, plugin_name, key, _DEFAULT_VALUE
|
||||
)
|
||||
|
||||
def get_publish_attribute_definitions(
|
||||
self,
|
||||
|
|
@ -1064,6 +1047,53 @@ class CreateModel:
|
|||
CreatorItem.from_creator(creator)
|
||||
)
|
||||
|
||||
def _set_instances_create_attr_values(self, instance_ids, key, value):
|
||||
with self._create_context.bulk_value_changes(CREATE_EVENT_SOURCE):
|
||||
for instance_id in instance_ids:
|
||||
instance = self._get_instance_by_id(instance_id)
|
||||
creator_attributes = instance["creator_attributes"]
|
||||
attr_def = creator_attributes.get_attr_def(key)
|
||||
if (
|
||||
attr_def is None
|
||||
or not attr_def.is_value_def
|
||||
or not attr_def.visible
|
||||
or not attr_def.enabled
|
||||
):
|
||||
continue
|
||||
|
||||
if value is _DEFAULT_VALUE:
|
||||
creator_attributes[key] = attr_def.default
|
||||
|
||||
elif attr_def.is_value_valid(value):
|
||||
creator_attributes[key] = value
|
||||
|
||||
def _set_instances_publish_attr_values(
|
||||
self, instance_ids, plugin_name, key, value
|
||||
):
|
||||
with self._create_context.bulk_value_changes(CREATE_EVENT_SOURCE):
|
||||
for instance_id in instance_ids:
|
||||
if instance_id is None:
|
||||
instance = self._create_context
|
||||
else:
|
||||
instance = self._get_instance_by_id(instance_id)
|
||||
plugin_val = instance.publish_attributes[plugin_name]
|
||||
attr_def = plugin_val.get_attr_def(key)
|
||||
# Ignore if attribute is not available or enabled/visible
|
||||
# on the instance, or the value is not valid for definition
|
||||
if (
|
||||
attr_def is None
|
||||
or not attr_def.is_value_def
|
||||
or not attr_def.visible
|
||||
or not attr_def.enabled
|
||||
):
|
||||
continue
|
||||
|
||||
if value is _DEFAULT_VALUE:
|
||||
plugin_val[key] = attr_def.default
|
||||
|
||||
elif attr_def.is_value_valid(value):
|
||||
plugin_val[key] = value
|
||||
|
||||
def _cc_added_instance(self, event):
|
||||
instance_ids = {
|
||||
instance.id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue