Skip to content

Commit

Permalink
SHOT-4280/SG-32772: Show Published Files that have no Task or Link (#58)
Browse files Browse the repository at this point in the history
* Fix query filter for allowing Entity Link and Task to be None
* Add config setting to specify publish file filter that defaults to requiring Published Files to have a Task and Linked Entity
* This config setting can be modified to allow Task or Link to be None
  • Loading branch information
staceyoue authored Nov 14, 2023
1 parent ddcea64 commit f2fbc80
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
45 changes: 40 additions & 5 deletions hooks/get_published_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class GetPublishedFiles(HookBaseClass):
""""""
"""Hook to specify the query to retrieve Published Files for the app."""

def get_published_files_for_items(self, items, data_retriever=None):
"""
Expand All @@ -38,19 +38,54 @@ def get_published_files_for_items(self, items, data_retriever=None):
entities = []
names = []
tasks = []
none_entity = False
none_task = False
pf_types = []
for file_item in items:
entities.append(file_item.sg_data["entity"])
# Required published file fields are name and published file type. There will be
# an api error if these are not set.
names.append(file_item.sg_data["name"])
tasks.append(file_item.sg_data["task"])
pf_types.append(file_item.sg_data["published_file_type"])

# Optional fields are linked entity and task.
entity = file_item.sg_data["entity"]
if entity:
entities.append(entity)
else:
none_entity = True

task = file_item.sg_data["task"]
if task:
tasks.append(task)
else:
none_task = True

# Build the entity filters
entity_filters = []
if entities:
entity_filters.append(["entity", "in", entities])
if none_entity:
entity_filters.append(["entity", "is", None])

# Build the task filters
task_filters = []
if tasks:
task_filters.append(["task", "in", tasks])
if none_task:
task_filters.append(["task", "is", None])

# Published files will be found by their entity, name, task and published file type.
filters = [
["entity", "in", entities],
["name", "in", names],
["task", "in", tasks],
["published_file_type", "in", pf_types],
{
"filter_operator": "any",
"filters": entity_filters,
},
{
"filter_operator": "any",
"filters": task_filters,
},
]

# Get the query fields. This assumes all file items in the list have the same fields.
Expand Down
12 changes: 12 additions & 0 deletions info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ configuration:
description: List of Published File fields returned when querying ShotGrid for published file history.
These fields will also be used when scanning the scene to get the current scene elements.

published_file_filters:
type: list
description: List of filters that will be applied when querying ShotGrid for Published Files based on
the items found in the scene. To show Published Files without a Task, remove the default
filter to exclude Published Files that do not have a Task, and similarly for Link entity.
values:
type: shotgun_filter
allows_empty: True
default_value:
- [task, is_not, null]
- [entity, is_not, null]

group_by:
type: str
default_value: project
Expand Down
20 changes: 19 additions & 1 deletion python/tk_multi_breakdown2/api/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ def get_published_files_from_file_paths(
if extra_fields is not None:
fields += extra_fields

# Get the published file filters to pass to the query
filters = self.get_published_file_filters()

# Option to run this in a background task since this can take some time to execute.
if bg_task_manager:
# Execute the request async and return the task id for the operation.
return bg_task_manager.add_task(
sgtk.util.find_publish,
task_args=[self._bundle.sgtk, file_paths],
task_kwargs={"fields": fields, "only_current_project": False},
task_kwargs={
"filters": filters,
"fields": fields,
"only_current_project": False,
},
)

# No background task manager provided, execute the request synchronously and return
Expand Down Expand Up @@ -157,6 +164,17 @@ def get_published_file_fields(self):
"published_file_fields", []
)

def get_published_file_filters(self):
"""
Get additional filters to pass to the query to retrieve the published files when
scanning the scene.
:return: The published file filters.
:rtype: List[List[dict]]
"""

return self._bundle.get_setting("published_file_filters", [])

def get_latest_published_file(self, item, data_retriever=None):
"""
Get the latest available published file according to the current item context.
Expand Down
6 changes: 6 additions & 0 deletions python/tk_multi_breakdown2/file_item_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,9 @@ def _on_data_retriever_work_failed(self, uid, error_msg):
elif uid == self.__pending_latest_published_files_data_request:
self.__pending_latest_published_files_data_request = None

if error_msg:
raise Exception(error_msg)

def _on_background_task_completed(self, uid, group_id, result):
"""
Callback triggered when the background manager has finished doing some task. The only
Expand Down Expand Up @@ -1532,6 +1535,9 @@ def _on_background_task_failed(self, uid, group_id, msg, stack_trace):
self.__pending_published_file_data_request = None
self._finish_reload()

if msg:
raise Exception(msg)

def _on_background_task_group_finished(self, group_id):
"""
Slot triggered when the background manager finishes all tasks within a group.
Expand Down

0 comments on commit f2fbc80

Please sign in to comment.