diff --git a/openpype/modules/ftrack/plugins/publish/integrate_ftrack_description.py b/openpype/modules/ftrack/plugins/publish/integrate_ftrack_description.py
new file mode 100644
index 0000000000..c6a3d47f66
--- /dev/null
+++ b/openpype/modules/ftrack/plugins/publish/integrate_ftrack_description.py
@@ -0,0 +1,84 @@
+"""
+Requires:
+ context > comment
+ context > ftrackSession
+ instance > ftrackIntegratedAssetVersionsData
+"""
+
+import sys
+
+import six
+import pyblish.api
+
+
+class IntegrateFtrackDescription(pyblish.api.InstancePlugin):
+ """Add description to AssetVersions in Ftrack."""
+
+ # Must be after integrate asset new
+ order = pyblish.api.IntegratorOrder + 0.4999
+ label = "Integrate Ftrack description"
+ families = ["ftrack"]
+ optional = True
+
+ # Can be set in settings:
+ # - Allows `intent` and `comment` keys
+ description_template = "{comment}"
+
+ def process(self, instance):
+ # Check if there are any integrated AssetVersion entities
+ asset_versions_key = "ftrackIntegratedAssetVersionsData"
+ asset_versions_data_by_id = instance.data.get(asset_versions_key)
+ if not asset_versions_data_by_id:
+ self.log.info("There are any integrated AssetVersions")
+ return
+
+ comment = (instance.context.data.get("comment") or "").strip()
+ if not comment:
+ self.log.info("Comment is not set.")
+ else:
+ self.log.debug("Comment is set to `{}`".format(comment))
+
+ session = instance.context.data["ftrackSession"]
+
+ intent = instance.context.data.get("intent")
+ intent_label = None
+ if intent and isinstance(intent, dict):
+ intent_val = intent.get("value")
+ intent_label = intent.get("label")
+ else:
+ intent_val = intent
+
+ if not intent_label:
+ intent_label = intent_val or ""
+
+ # if intent label is set then format comment
+ # - it is possible that intent_label is equal to "" (empty string)
+ if intent_label:
+ self.log.debug(
+ "Intent label is set to `{}`.".format(intent_label)
+ )
+
+ else:
+ self.log.debug("Intent is not set.")
+
+ for asset_version_data in asset_versions_data_by_id.values():
+ asset_version = asset_version_data["asset_version"]
+
+ # Backwards compatibility for older settings using
+ # attribute 'note_with_intent_template'
+ comment = self.description_template.format(**{
+ "intent": intent_label,
+ "comment": comment
+ })
+ asset_version["comment"] = comment
+
+ try:
+ session.commit()
+ self.log.debug("Comment added to AssetVersion \"{}\"".format(
+ str(asset_version)
+ ))
+ except Exception:
+ tp, value, tb = sys.exc_info()
+ session.rollback()
+ session._configure_locations()
+ six.reraise(tp, value, tb)
diff --git a/openpype/modules/ftrack/plugins/publish/integrate_ftrack_note.py b/openpype/modules/ftrack/plugins/publish/integrate_ftrack_note.py
index 56a7a89e16..952b21546d 100644
--- a/openpype/modules/ftrack/plugins/publish/integrate_ftrack_note.py
+++ b/openpype/modules/ftrack/plugins/publish/integrate_ftrack_note.py
@@ -1,7 +1,17 @@
+"""
+Requires:
+ context > hostName
+ context > appName
+ context > appLabel
+ context > comment
+ context > ftrackSession
+ instance > ftrackIntegratedAssetVersionsData
+"""
+
import sys
-import json
-import pyblish.api
+
import six
+import pyblish.api
class IntegrateFtrackNote(pyblish.api.InstancePlugin):
@@ -29,36 +39,34 @@ class IntegrateFtrackNote(pyblish.api.InstancePlugin):
self.log.info("There are any integrated AssetVersions")
return
- host_name = instance.context.data["hostName"]
- app_name = instance.context.data["appName"]
- app_label = instance.context.data["appLabel"]
- comment = (instance.context.data.get("comment") or "").strip()
+ context = instance.context
+ host_name = context.data["hostName"]
+ app_name = context.data["appName"]
+ app_label = context.data["appLabel"]
+ comment = (context.data.get("comment") or "").strip()
if not comment:
self.log.info("Comment is not set.")
else:
self.log.debug("Comment is set to `{}`".format(comment))
- session = instance.context.data["ftrackSession"]
+ session = context.data["ftrackSession"]
intent = instance.context.data.get("intent")
+ intent_label = None
if intent and isinstance(intent, dict):
intent_val = intent.get("value")
intent_label = intent.get("label")
else:
- intent_val = intent_label = intent
+ intent_val = intent
- final_intent_label = None
- if intent_val:
- final_intent_label = self.get_intent_label(session, intent_val)
-
- if final_intent_label is None:
- final_intent_label = intent_label
+ if not intent_label:
+ intent_label = intent_val or ""
# if intent label is set then format comment
# - it is possible that intent_label is equal to "" (empty string)
- if final_intent_label:
+ if intent_label:
self.log.debug(
- "Intent label is set to `{}`.".format(final_intent_label)
+ "Intent label is set to `{}`.".format(intent_label)
)
else:
@@ -102,7 +110,7 @@ class IntegrateFtrackNote(pyblish.api.InstancePlugin):
if template is None:
template = self.note_with_intent_template
format_data = {
- "intent": final_intent_label,
+ "intent": intent_label,
"comment": comment,
"host_name": host_name,
"app_name": app_name,
@@ -128,40 +136,3 @@ class IntegrateFtrackNote(pyblish.api.InstancePlugin):
session.rollback()
session._configure_locations()
six.reraise(tp, value, tb)
-
- 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
-
- configuration = json.loads(config)
- items = configuration.get("data")
- if not items:
- return
-
- if isinstance(items, six.string_types):
- items = json.loads(items)
-
- intent_label = None
- for item in items:
- if item["value"] == intent_value:
- intent_label = item["menu"]
- break
-
- return intent_label
diff --git a/openpype/settings/defaults/project_settings/ftrack.json b/openpype/settings/defaults/project_settings/ftrack.json
index 9b350ec88d..31d6a70ac7 100644
--- a/openpype/settings/defaults/project_settings/ftrack.json
+++ b/openpype/settings/defaults/project_settings/ftrack.json
@@ -357,6 +357,12 @@
"note_template": "{intent}: {comment}",
"note_labels": []
},
+ "IntegrateFtrackDescription": {
+ "enabled": false,
+ "optional": true,
+ "active": true,
+ "description_template": "{comment}"
+ },
"ValidateFtrackAttributes": {
"enabled": false,
"ftrack_custom_attributes": {}
diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_ftrack.json b/openpype/settings/entities/schemas/projects_schema/schema_project_ftrack.json
index 0ed2fb3536..5ce9b24b4b 100644
--- a/openpype/settings/entities/schemas/projects_schema/schema_project_ftrack.json
+++ b/openpype/settings/entities/schemas/projects_schema/schema_project_ftrack.json
@@ -756,6 +756,44 @@
}
]
},
+ {
+ "type": "dict",
+ "collapsible": true,
+ "checkbox_key": "enabled",
+ "key": "IntegrateFtrackDescription",
+ "label": "Integrate Ftrack Description",
+ "is_group": true,
+ "children": [
+ {
+ "type": "boolean",
+ "key": "enabled",
+ "label": "Enabled"
+ },
+ {
+ "type": "label",
+ "label": "Add description to integrated AssetVersion."
+ },
+ {
+ "type": "boolean",
+ "key": "optional",
+ "label": "Optional"
+ },
+ {
+ "type": "boolean",
+ "key": "active",
+ "label": "Active"
+ },
+ {
+ "type": "label",
+ "label": "Template may contain formatting keys intent and comment."
+ },
+ {
+ "type": "text",
+ "key": "description_template",
+ "label": "Description template"
+ }
+ ]
+ },
{
"type": "dict",
"collapsible": true,