Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions client/ayon_core/tools/sceneinventory/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from ayon_core.style import get_default_entity_icon_color
from ayon_core.tools.utils import get_qt_icon
from ayon_core.tools.utils.lib import format_version
from ayon_core.pipeline import template_data
from ayon_core.lib import filter_profiles
from ayon_core.settings import get_project_settings

ITEM_ID_ROLE = QtCore.Qt.UserRole + 1
NAME_COLOR_ROLE = QtCore.Qt.UserRole + 2
Expand Down Expand Up @@ -127,13 +130,55 @@
def outdated(self, item):
return item.get("isOutdated", True)

def _get_repre_info_template_data(self, repre_info):
fake_folder_entity = {
"name": repre_info.folder_name,
"id": repre_info.folder_id,
"folderType": repre_info.folder_type,
"path": repre_info.folder_path
}

folder_data = template_data.get_folder_template_data(

Check failure on line 141 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (F823)

client/ayon_core/tools/sceneinventory/model.py:141:23: F823 Local variable `template_data` referenced before assignment
fake_folder_entity,
self._controller.get_current_project_name()
)

template_data = {
"product": {
"name": repre_info.product_name,
"type": repre_info.product_type,
},
"representation": {
"name": repre_info.representation_name,
}
}
template_data .update(folder_data)
return template_data

Check failure on line 156 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (W291)

client/ayon_core/tools/sceneinventory/model.py:156:29: W291 Trailing whitespace

def refresh(self, selected=None):
"""Refresh the model"""
# for debugging or testing, injecting items from outside
container_items = self._controller.get_container_items()

self._clear_items()

# fetch the label settings

settings = get_project_settings(
Copy link
Member

@iLLiCiTiT iLLiCiTiT Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole shebang of getting the template should be implemented in controller not in UI.

Here should be just

group_name_template = self._controller.get_label_template()

Copy link
Member

@iLLiCiTiT iLLiCiTiT Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe even better, the container items should be returned with the label prepared...

UI should only show what controller (and models) prepare for data. In ideal case scenario should not make any calls using ayon_api or call host method.

self._controller.get_current_project_name())

selected_profile = filter_profiles(
settings["core"]["tools"]["inventory"]["profiles"],
{
"host_name": self._controller.get_host().name,
"task_name": self._controller.get_current_context()["task_name"]

Check failure on line 173 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (E501)

client/ayon_core/tools/sceneinventory/model.py:173:80: E501 Line too long (80 > 79)
},
keys_order=["host_name", "task_name"])
group_name_template = "{folder[name]}_{product[name]}: ({representation[name]})"

Check failure on line 176 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (E501)

client/ayon_core/tools/sceneinventory/model.py:176:80: E501 Line too long (88 > 79)
if selected_profile is not None:
group_name_template = selected_profile["inventory_name_format"]

Check failure on line 179 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (W293)

client/ayon_core/tools/sceneinventory/model.py:179:1: W293 Blank line contains whitespace

items_by_repre_id = {}

Check failure on line 181 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (E303)

client/ayon_core/tools/sceneinventory/model.py:181:9: E303 Too many blank lines (2)
project_names = set()
repre_ids_by_project = collections.defaultdict(set)
version_items_by_project = collections.defaultdict(dict)
Expand Down Expand Up @@ -250,11 +295,9 @@
status_name = None

else:
group_name = "{}_{}: ({})".format(
repre_info.folder_path.rsplit("/")[-1],
repre_info.product_name,
repre_info.representation_name
)
template_data = self._get_repre_info_template_data(repre_info)

Check failure on line 298 in client/ayon_core/tools/sceneinventory/model.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (E501)

client/ayon_core/tools/sceneinventory/model.py:298:80: E501 Line too long (82 > 79)
group_name = group_name_template.format(**template_data)

item_icon = valid_item_icon

version_items = (
Expand Down
9 changes: 9 additions & 0 deletions client/ayon_core/tools/sceneinventory/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def representations_parent_ids_qraphql_query():
folder_field = product_field.add_field("folder")
folder_field.add_field("id")
folder_field.add_field("path")
folder_field.add_field("folderType")
return query


Expand Down Expand Up @@ -123,6 +124,8 @@ def __init__(
self,
folder_id,
folder_path,
folder_name,
folder_type,
product_id,
product_name,
product_type,
Expand All @@ -132,6 +135,8 @@ def __init__(
):
self.folder_id = folder_id
self.folder_path = folder_path
self.folder_name = folder_name
self.folder_type = folder_type
self.product_id = product_id
self.product_name = product_name
self.product_type = product_type
Expand Down Expand Up @@ -250,6 +255,8 @@ def get_representation_info_items(self, project_name, representation_ids):
kwargs = {
"folder_id": None,
"folder_path": None,
"folder_name": None,
"folder_type": None,
"product_id": None,
"product_name": None,
"product_type": None,
Expand All @@ -264,6 +271,8 @@ def get_representation_info_items(self, project_name, representation_ids):
if folder:
kwargs["folder_id"] = folder["id"]
kwargs["folder_path"] = folder["path"]
kwargs["folder_name"] = folder["path"].split("/")[-1]
kwargs["folder_type"] = folder["folderType"]
if product:
group = product["attrib"]["productGroup"]
kwargs["product_id"] = product["id"]
Expand Down
34 changes: 32 additions & 2 deletions server/settings/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,29 @@ class PublishToolModel(BaseSettingsModel):
)


class InventoryTemplateNameProfile(BaseSettingsModel):
_layout = "expanded"
host_names: list[str] = SettingsField(
title="Host names",
default_factory=list
)
task_name: list[str] = SettingsField(
title="Task names",
default_factory=list
)
template: str = SettingsField(
title="Template",
default_factory=str
)


class InventoryToolModel(BaseSettingsModel):
profiles: list[InventoryTemplateNameProfile] = SettingsField(
default_factory=list,
title="Inventory label templates"
)


class GlobalToolsModel(BaseSettingsModel):
ayon_menu: AYONMenuModel = SettingsField(
default_factory=AYONMenuModel,
Expand All @@ -389,6 +412,10 @@ class GlobalToolsModel(BaseSettingsModel):
default_factory=PublishToolModel,
title="Publish"
)
inventory: InventoryToolModel = SettingsField(
default_factory=InventoryToolModel,
title="Inventory"
)


DEFAULT_TOOLS_VALUES = {
Expand Down Expand Up @@ -679,7 +706,10 @@ class GlobalToolsModel(BaseSettingsModel):
"task_names": [],
"template_name": "simpleUnrealTextureHero"
}
],
"comment_minimum_required_chars": 0,
]
},
"comment_minimum_required_chars": 0,
"inventory": {
"profiles": []
}
}
Loading