mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
integrate ftrack note use label from ftrack's custom attribute configuration
This commit is contained in:
parent
b61debdc95
commit
12557526c3
1 changed files with 64 additions and 7 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
import json
|
||||
import pyblish.api
|
||||
import six
|
||||
|
||||
|
|
@ -18,6 +19,47 @@ class IntegrateFtrackNote(pyblish.api.InstancePlugin):
|
|||
# - note label must exist in Ftrack
|
||||
note_labels = []
|
||||
|
||||
def get_intent_label(self, session, intent_value):
|
||||
if not intent_value:
|
||||
return
|
||||
|
||||
intent_configurations = session.query(
|
||||
"CustomAttributeConfiguration where key is intent"
|
||||
).all()
|
||||
if not intent_configurations:
|
||||
return
|
||||
|
||||
intent_configuration = intent_configurations[0]
|
||||
if len(intent_configuration) > 1:
|
||||
self.log.warning((
|
||||
"Found more than one `intent` custom attribute."
|
||||
" Using first found."
|
||||
))
|
||||
|
||||
config = intent_configuration.get("config")
|
||||
if not config:
|
||||
return
|
||||
|
||||
items = config.get("data")
|
||||
if not items:
|
||||
return
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
string_type = basestring
|
||||
else:
|
||||
string_type = str
|
||||
|
||||
if isinstance(items, string_type):
|
||||
items = json.loads(items)
|
||||
|
||||
intent_label = None
|
||||
for item in items:
|
||||
if item["value"] == intent_value:
|
||||
intent_label = item["menu"]
|
||||
break
|
||||
|
||||
return intent_label
|
||||
|
||||
def process(self, instance):
|
||||
comment = (instance.context.data.get("comment") or "").strip()
|
||||
if not comment:
|
||||
|
|
@ -26,17 +68,33 @@ class IntegrateFtrackNote(pyblish.api.InstancePlugin):
|
|||
|
||||
self.log.debug("Comment is set to `{}`".format(comment))
|
||||
|
||||
intent = instance.context.data.get("intent")
|
||||
if intent:
|
||||
msg = "Intent is set to `{}` and was added to comment.".format(
|
||||
intent
|
||||
)
|
||||
session = instance.context.data["ftrackSession"]
|
||||
|
||||
intent_val = instance.context.data.get("intent", {}).get("value")
|
||||
intent_label = None
|
||||
if intent_val:
|
||||
intent_label = self.get_intent_label(session, intent_val)
|
||||
if intent_label is None:
|
||||
intent_label = intent_val
|
||||
|
||||
# if intent label is set then format comment
|
||||
# - it is possible that intent_label is equal to "" (empty string)
|
||||
if intent_label:
|
||||
msg = "Intent label is to `{}`.".format(intent_label)
|
||||
comment = self.note_with_intent_template.format(**{
|
||||
"intent": intent,
|
||||
"intent": intent_val,
|
||||
"comment": comment
|
||||
})
|
||||
|
||||
elif intent_val:
|
||||
msg = (
|
||||
"Intent is set to `{}` and was not added"
|
||||
" to comment because label is set to `{}`."
|
||||
).format(intent_val, intent_label)
|
||||
|
||||
else:
|
||||
msg = "Intent is not set."
|
||||
|
||||
self.log.debug(msg)
|
||||
|
||||
asset_versions_key = "ftrackIntegratedAssetVersions"
|
||||
|
|
@ -45,7 +103,6 @@ class IntegrateFtrackNote(pyblish.api.InstancePlugin):
|
|||
self.log.info("There are any integrated AssetVersions")
|
||||
return
|
||||
|
||||
session = instance.context.data["ftrackSession"]
|
||||
user = session.query(
|
||||
"User where username is \"{}\"".format(session.api_user)
|
||||
).first()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue