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
49 changes: 44 additions & 5 deletions ayon_api/_api_helpers/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ def get_entity_lists(
active: Optional[bool] = None,
fields: Optional[Iterable[str]] = None,
) -> Generator[dict[str, Any], None, None]:
"""Fetch entity lists from server.
"""Fetch entity lists from AYON server.

Warnings:
You can't get list items for lists with different 'entityType' in
one call.

Notes:
To get list items, you have to pass 'items' field or
'items.{sub-fields you want}' to 'fields' argument.

Args:
project_name (str): Project name where entity lists are.
Expand All @@ -42,7 +50,30 @@ def get_entity_lists(
"""
if fields is None:
fields = self.get_default_fields_for_type("entityList")
fields = set(fields)

# List does not have 'attrib' field but has 'allAttrib' field
# which is json string and contains only values that are set
o_fields = tuple(fields)
fields = set()
requires_attrib = False
for field in o_fields:
if field == "attrib" or field.startswith("attrib."):
requires_attrib = True
field = "allAttrib"
fields.add(field)

if "items" in fields:
fields.discard("items")
fields |= {
"items.id",
"items.entityId",
"items.entityType",
"items.position",
}

available_attribs = []
if requires_attrib:
available_attribs = self.get_attributes_for_type("list")

if active is not None:
fields.add("active")
Expand All @@ -66,6 +97,15 @@ def get_entity_lists(
if isinstance(attributes, str):
entity_list["attributes"] = json.loads(attributes)

if requires_attrib:
all_attrib = json.loads(
entity_list.get("allAttrib") or "{}"
)
entity_list["attrib"] = {
attrib_name: all_attrib.get(attrib_name)
for attrib_name in available_attribs
}

self._convert_entity_data(entity_list)

yield entity_list
Expand Down Expand Up @@ -170,9 +210,8 @@ def create_entity_list(
kwargs[key] = value

response = self.post(
f"projects/{project_name}/lists/{list_id}/items",
f"projects/{project_name}/lists",
**kwargs

)
response.raise_for_status()
return list_id
Expand Down Expand Up @@ -343,7 +382,7 @@ def update_entity_list_items(
mode (EntityListItemMode): Mode of items update.

"""
response = self.post(
response = self.patch(
f"projects/{project_name}/lists/{list_id}/items",
items=items,
mode=mode,
Expand Down
5 changes: 1 addition & 4 deletions ayon_api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
DEFAULT_ENTITY_LIST_FIELDS = {
"id",
"count",
"allAttrib",
"attributes",
"active",
"createdBy",
Expand All @@ -259,8 +260,4 @@
"tags",
"updatedAt",
"updatedBy",
"items.id",
"items.entityId",
"items.entityType",
"items.position",
}
2 changes: 2 additions & 0 deletions ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,8 @@ def get_default_fields_for_type(self, entity_type: str) -> set[str]:

elif entity_type == "entityList":
entity_type_defaults = set(DEFAULT_ENTITY_LIST_FIELDS)
# Attributes scope is 'list'
entity_type = "list"

else:
raise ValueError(f"Unknown entity type \"{entity_type}\"")
Expand Down