diff --git a/ayon_api/_api_helpers/lists.py b/ayon_api/_api_helpers/lists.py index b6bd79265..df22e3844 100644 --- a/ayon_api/_api_helpers/lists.py +++ b/ayon_api/_api_helpers/lists.py @@ -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. @@ -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") @@ -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 @@ -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 @@ -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, diff --git a/ayon_api/constants.py b/ayon_api/constants.py index 21d75e324..e39fc175f 100644 --- a/ayon_api/constants.py +++ b/ayon_api/constants.py @@ -247,6 +247,7 @@ DEFAULT_ENTITY_LIST_FIELDS = { "id", "count", + "allAttrib", "attributes", "active", "createdBy", @@ -259,8 +260,4 @@ "tags", "updatedAt", "updatedBy", - "items.id", - "items.entityId", - "items.entityType", - "items.position", } diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 9df64fbb2..80d940086 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -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}\"")