Skip to content

Commit c62ea85

Browse files
authored
Merge pull request #285 from ynput/enhancement/helper-function-for-new-task
Operations: Added `new_task_entity`
2 parents 464f282 + 921b714 commit c62ea85

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

ayon_api/operations.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .server_api import ServerAPI
1616
from .typing import (
1717
NewFolderDict,
18+
NewTaskDict,
1819
NewProductDict,
1920
NewVersionDict,
2021
NewRepresentationDict,
@@ -76,6 +77,7 @@ def new_folder_entity(
7677
folder_type: str,
7778
parent_id: Optional[str] = None,
7879
status: Optional[str] = None,
80+
active: Optional[bool] = None,
7981
tags: Optional[list[str]] = None,
8082
attribs: Optional[dict[str, Any]] = None,
8183
data: Optional[dict[str, Any]] = None,
@@ -89,6 +91,7 @@ def new_folder_entity(
8991
folder_type (str): Type of folder.
9092
parent_id (Optional[str]): Parent folder id.
9193
status (Optional[str]): Product status.
94+
active (Optional[bool]): Active status..
9295
tags (Optional[list[str]]): List of tags.
9396
attribs (Optional[dict[str, Any]]): Explicitly set attributes
9497
of folder.
@@ -125,6 +128,67 @@ def new_folder_entity(
125128
output["status"] = status
126129
if tags:
127130
output["tags"] = tags
131+
if active is not None:
132+
output["active"] = active
133+
return output
134+
135+
136+
def new_task_entity(
137+
name: str,
138+
task_type: str,
139+
folder_id: str,
140+
*,
141+
label: Optional[str] = None,
142+
assignees: Optional[list[str]] = None,
143+
attrib: Optional[dict[str, Any]] = None,
144+
data: Optional[dict[str, Any]] = None,
145+
tags: Optional[list[str]] = None,
146+
status: Optional[str] = None,
147+
active: Optional[bool] = None,
148+
thumbnail_id: Optional[str] = None,
149+
task_id: Optional[str] = None,
150+
) -> NewTaskDict:
151+
"""Create skeleton data of task entity.
152+
153+
Args:
154+
name (str): Folder name.
155+
task_type (str): Task type.
156+
folder_id (str): Parent folder id.
157+
label (Optional[str]): Label of folder.
158+
assignees (Optional[list[str]]): Task assignees.
159+
attrib (Optional[dict[str, Any]]): Task attributes.
160+
data (Optional[dict[str, Any]]): Task data.
161+
tags (Optional[list[str]]): Task tags.
162+
status (Optional[str]): Task status.
163+
active (Optional[bool]): Task active state.
164+
thumbnail_id (Optional[str]): Task thumbnail id.
165+
task_id (Optional[str]): Task id. If not passed new id is
166+
generated.
167+
168+
Returns:
169+
NewTaskDict: Skeleton of task entity.
170+
171+
"""
172+
if not task_id:
173+
task_id = create_entity_id()
174+
output = {
175+
"id": task_id,
176+
"name": name,
177+
"taskType": task_type,
178+
"folderId": folder_id,
179+
}
180+
for key, value in (
181+
("label", label),
182+
("attrib", attrib),
183+
("data", data),
184+
("tags", tags),
185+
("status", status),
186+
("assignees", assignees),
187+
("active", active),
188+
("thumbnailId", thumbnail_id),
189+
):
190+
if value is not None:
191+
output[key] = value
128192
return output
129193

130194

@@ -1046,6 +1110,10 @@ def create_task(
10461110
"taskType": task_type,
10471111
"folderId": folder_id,
10481112
}
1113+
if tags is not None:
1114+
tags = list(tags)
1115+
if assignees is not None:
1116+
assignees = list(assignees)
10491117
for key, value in (
10501118
("label", label),
10511119
("attrib", attrib),

ayon_api/typing.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,21 @@ class NewFolderDict(TypedDict):
362362
tags: NotRequired[list[str]]
363363

364364

365+
class NewTaskDict(TypedDict):
366+
id: str
367+
name: str
368+
task_type: str
369+
folder_id: str
370+
label: NotRequired[str]
371+
assignees: NotRequired[list[str]]
372+
attrib: NotRequired[dict[str, Any]]
373+
data: NotRequired[dict[str, Any]]
374+
thumbnailId: NotRequired[str]
375+
active: NotRequired[bool]
376+
status: NotRequired[str]
377+
tags: NotRequired[list[str]]
378+
379+
365380
class NewProductDict(TypedDict):
366381
id: str
367382
name: str

0 commit comments

Comments
 (0)