From 3389f745621939ca5f3730521217abbf275d5088 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 8 Oct 2025 16:09:53 +0200 Subject: [PATCH 1/4] added workfiles methods to operations --- ayon_api/operations.py | 140 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/ayon_api/operations.py b/ayon_api/operations.py index dbdc99985..5a514162e 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -1544,3 +1544,143 @@ def delete_representation( return self.delete_entity( project_name, "representation", representation_id ) + + def create_workfile_info( + self, + project_name: str, + path: str, + task_id: str, + *, + thumbnail_id: Optional[str] = None, + attrib: Optional[dict[str, Any]] = None, + data: Optional[dict[str, Any]] = None, + tags: Optional[list[str]] = None, + status: Optional[str] = None, + active: Optional[bool] = None, + workfile_id: Optional[str] = None, + ) -> CreateOperation: + """Create new workfile. + + Args: + project_name (str): Project name. + path (str): Representation name. + task_id (str): Parent task id. + thumbnail_id (Optional[str]): Thumbnail id. + attrib (Optional[dict[str, Any]]): Representation attributes. + data (Optional[dict[str, Any]]): Representation data. + tags (Optional[Iterable[str]]): Representation tags. + status (Optional[str]): Representation status. + active (Optional[bool]): Representation active state. + workfile_id (Optional[str]): Workfile info id. If not + passed new id is generated. + + Returns: + CreateOperation: Object of create operation. + + """ + if workfile_id is None: + workfile_id = create_entity_id() + + create_data = { + "id": workfile_id, + "path": path, + "taskId": task_id, + } + for key, value in ( + ("thumbnailId", thumbnail_id), + ("attrib", attrib), + ("data", data), + ("tags", tags), + ("status", status), + ("active", active), + ): + if value is not None: + create_data[key] = value + + return self.create_entity( + project_name, + "workfile", + create_data + ) + + def update_workfile_info( + self, + project_name: str, + workfile_id: str, + path: Optional[str] = None, + task_id: Optional[str] = None, + attrib: Optional[dict[str, Any]] = None, + data: Optional[dict[str, Any]] = None, + tags: Optional[Iterable[str]] = None, + status: Optional[str] = None, + active: Optional[bool] = None, + thumbnail_id: Optional[str] = NOT_SET, + created_by: Optional[str] = None, + updated_by: Optional[str] = None, + ) -> UpdateOperation: + """Update workfile info entity on server. + + Update of ``data`` will override existing value on folder entity. + + Update of ``attrib`` does change only passed attributes. If you want + to unset value, use ``None``. + + Args: + project_name (str): Project name. + workfile_id (str): Workfile id. + path (Optional[str]): New rootless workfile path.. + task_id (Optional[str]): New parent task id. + attrib (Optional[dict[str, Any]]): New attributes. + data (Optional[dict[str, Any]]): New data. + tags (Optional[Iterable[str]]): New tags. + status (Optional[str]): New status. + active (Optional[bool]): New active state. + thumbnail_id (Optional[str]): New thumbnail id. + created_by (Optional[str]): New created by username. + updated_by (Optional[str]): New updated by username. + + Returns: + UpdateOperation: Object of update operation. + + """ + update_data = {} + for key, value in ( + ("path", path), + ("taskId", task_id), + ("attrib", attrib), + ("data", data), + ("tags", tags), + ("status", status), + ("active", active), + ("thumbnailId", thumbnail_id), + ("createdBy", created_by), + ("updatedBy", updated_by), + ): + if value is not None: + update_data[key] = value + + return self.update_entity( + project_name, + "workfile", + workfile_id, + update_data + ) + + def delete_workfile( + self, + project_name: str, + workfile_id: str, + ) -> DeleteOperation: + """Delete representation. + + Args: + project_name (str): Project name. + workfile_id (str): Workfile info id to delete. + + Returns: + DeleteOperation: Object of delete operation. + + """ + return self.delete_entity( + project_name, "workfile", workfile_id + ) From c6551d3483ee6ee81e9cafabbb5cf89872d91f23 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:03:13 +0200 Subject: [PATCH 2/4] rename info to entity --- ayon_api/operations.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ayon_api/operations.py b/ayon_api/operations.py index 5a514162e..aa03d26a8 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -340,7 +340,7 @@ def new_representation_entity( return output -def new_workfile_info( +def new_workfile_entity( filepath: str, task_id: str, status: Optional[str] = None, @@ -396,6 +396,28 @@ def new_workfile_info( return output +def new_workfile_info( + filepath: str, + task_id: str, + status: Optional[str] = None, + tags: Optional[list[str]] = None, + attribs: Optional[dict[str, Any]] = None, + description: Optional[str] = None, + data: Optional[dict[str, Any]] = None, + entity_id: Optional[str] = None, +) -> NewWorkfileDict: + return new_workfile_entity( + filepath, + task_id, + status, + tags, + attribs, + description, + data, + entity_id, + ) + + class AbstractOperation(ABC): """Base operation class. @@ -1545,7 +1567,7 @@ def delete_representation( project_name, "representation", representation_id ) - def create_workfile_info( + def create_workfile_entity( self, project_name: str, path: str, @@ -1603,7 +1625,7 @@ def create_workfile_info( create_data ) - def update_workfile_info( + def update_workfile_entity( self, project_name: str, workfile_id: str, From 16b1e1e533d29d321bd71a93a435f880761c7e35 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:04:39 +0200 Subject: [PATCH 3/4] add entity to workfile --- ayon_api/operations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ayon_api/operations.py b/ayon_api/operations.py index aa03d26a8..c280c2bff 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -1688,12 +1688,12 @@ def update_workfile_entity( update_data ) - def delete_workfile( + def delete_workfile_entity( self, project_name: str, workfile_id: str, ) -> DeleteOperation: - """Delete representation. + """Delete workfile entity. Args: project_name (str): Project name. From 88408a9f1b125a29e10f8c5cb529d9932557fe4c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:04:47 +0200 Subject: [PATCH 4/4] change docstrings --- ayon_api/operations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ayon_api/operations.py b/ayon_api/operations.py index c280c2bff..9f68d00c4 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -1581,7 +1581,7 @@ def create_workfile_entity( active: Optional[bool] = None, workfile_id: Optional[str] = None, ) -> CreateOperation: - """Create new workfile. + """Create new workfile entity. Args: project_name (str): Project name. @@ -1640,7 +1640,7 @@ def update_workfile_entity( created_by: Optional[str] = None, updated_by: Optional[str] = None, ) -> UpdateOperation: - """Update workfile info entity on server. + """Update workfile entity on server. Update of ``data`` will override existing value on folder entity.