Skip to content

Commit 19e4cf4

Browse files
authored
Merge pull request #299 from ynput/bugfix/lists-methods
List methods: Overall fixes related to lists
2 parents 3aff822 + b6a6527 commit 19e4cf4

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

ayon_api/_api_helpers/lists.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ def get_entity_lists(
2626
active: Optional[bool] = None,
2727
fields: Optional[Iterable[str]] = None,
2828
) -> Generator[dict[str, Any], None, None]:
29-
"""Fetch entity lists from server.
29+
"""Fetch entity lists from AYON server.
30+
31+
Warnings:
32+
You can't get list items for lists with different 'entityType' in
33+
one call.
34+
35+
Notes:
36+
To get list items, you have to pass 'items' field or
37+
'items.{sub-fields you want}' to 'fields' argument.
3038
3139
Args:
3240
project_name (str): Project name where entity lists are.
@@ -42,7 +50,30 @@ def get_entity_lists(
4250
"""
4351
if fields is None:
4452
fields = self.get_default_fields_for_type("entityList")
45-
fields = set(fields)
53+
54+
# List does not have 'attrib' field but has 'allAttrib' field
55+
# which is json string and contains only values that are set
56+
o_fields = tuple(fields)
57+
fields = set()
58+
requires_attrib = False
59+
for field in o_fields:
60+
if field == "attrib" or field.startswith("attrib."):
61+
requires_attrib = True
62+
field = "allAttrib"
63+
fields.add(field)
64+
65+
if "items" in fields:
66+
fields.discard("items")
67+
fields |= {
68+
"items.id",
69+
"items.entityId",
70+
"items.entityType",
71+
"items.position",
72+
}
73+
74+
available_attribs = []
75+
if requires_attrib:
76+
available_attribs = self.get_attributes_for_type("list")
4677

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

100+
if requires_attrib:
101+
all_attrib = json.loads(
102+
entity_list.get("allAttrib") or "{}"
103+
)
104+
entity_list["attrib"] = {
105+
attrib_name: all_attrib.get(attrib_name)
106+
for attrib_name in available_attribs
107+
}
108+
69109
self._convert_entity_data(entity_list)
70110

71111
yield entity_list
@@ -170,9 +210,8 @@ def create_entity_list(
170210
kwargs[key] = value
171211

172212
response = self.post(
173-
f"projects/{project_name}/lists/{list_id}/items",
213+
f"projects/{project_name}/lists",
174214
**kwargs
175-
176215
)
177216
response.raise_for_status()
178217
return list_id
@@ -343,7 +382,7 @@ def update_entity_list_items(
343382
mode (EntityListItemMode): Mode of items update.
344383
345384
"""
346-
response = self.post(
385+
response = self.patch(
347386
f"projects/{project_name}/lists/{list_id}/items",
348387
items=items,
349388
mode=mode,

ayon_api/constants.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
DEFAULT_ENTITY_LIST_FIELDS = {
248248
"id",
249249
"count",
250+
"allAttrib",
250251
"attributes",
251252
"active",
252253
"createdBy",
@@ -259,8 +260,4 @@
259260
"tags",
260261
"updatedAt",
261262
"updatedBy",
262-
"items.id",
263-
"items.entityId",
264-
"items.entityType",
265-
"items.position",
266263
}

ayon_api/server_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,8 @@ def get_default_fields_for_type(self, entity_type: str) -> set[str]:
19561956

19571957
elif entity_type == "entityList":
19581958
entity_type_defaults = set(DEFAULT_ENTITY_LIST_FIELDS)
1959+
# Attributes scope is 'list'
1960+
entity_type = "list"
19591961

19601962
else:
19611963
raise ValueError(f"Unknown entity type \"{entity_type}\"")

0 commit comments

Comments
 (0)