Skip to content

Commit

Permalink
Merge pull request #14 from ynput/enhancement/adding_new_task_types
Browse files Browse the repository at this point in the history
Adding new task types and use default anatomy preset
  • Loading branch information
martastain authored Dec 28, 2023
2 parents 4eeb9a5 + 4bffb3b commit 6d95bf2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 32 deletions.
2 changes: 1 addition & 1 deletion server/frontend/src/PairingButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const PairingButton = ({ onPair, pairing }) => {
.post(`${addonData.baseUrl}/sync/${pairing.ayonProjectName}`)
.then((response) => {
setError(null)
onHide()
onPair()
})
.catch((error) => {
console.log(error)
Expand Down
21 changes: 15 additions & 6 deletions server/kitsu/anatomy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, TYPE_CHECKING

from ayon_server.exceptions import AyonException
from ayon_server.lib.postgres import Postgres
from ayon_server.settings.anatomy import Anatomy
from ayon_server.settings.anatomy.statuses import Status
from ayon_server.settings.anatomy.task_types import TaskType, default_task_types
Expand Down Expand Up @@ -162,6 +163,13 @@ def parse_attrib(source: dict[str, Any] | None = None):
return result


async def get_primary_anatomy_preset() -> Anatomy:
query = "SELECT * FROM anatomy_presets WHERE is_primary is TRUE"
async for row in Postgres.iterate(query):
return Anatomy(**row["data"])
return Anatomy()


async def get_kitsu_project_anatomy(
addon: "KitsuAddon",
kitsu_project_id: str,
Expand All @@ -180,10 +188,11 @@ async def get_kitsu_project_anatomy(
statuses = await parse_statuses(addon, kitsu_project_id)
task_types = await parse_task_types(addon, kitsu_project_id)

anatomy = Anatomy(
attributes=attributes,
task_types=task_types,
statuses=statuses,
)
anatomy_preset = await get_primary_anatomy_preset()
anatomy_dict = anatomy_preset.dict()

anatomy_dict["attributes"] = attributes
anatomy_dict["statuses"] = statuses
anatomy_dict["task_types"] = task_types

return anatomy
return Anatomy(**anatomy_dict)
7 changes: 5 additions & 2 deletions server/kitsu/init_pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ async def sync_request(
res = await Postgres.fetch(query, hash)

if res:

await update_event(
res[0][0],
description="Sync request from Kitsu",
Expand Down Expand Up @@ -125,4 +124,8 @@ async def init_pairing(
request.ayon_project_name,
)

await sync_request(project_name=request.ayon_project_name, user=user, kitsu_project_id=request.kitsu_project_id,)
await sync_request(
project_name=request.ayon_project_name,
user=user,
kitsu_project_id=request.kitsu_project_id,
)
1 change: 0 additions & 1 deletion server/kitsu/kitsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ async def delete(self, endpoint: str, **kwargs) -> httpx.Response:

async def patch(self, endpoint: str, **kwargs) -> httpx.Response:
return await self.request("patch", endpoint, **kwargs)

65 changes: 44 additions & 21 deletions server/kitsu/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from nxtools import logging

from ayon_server.entities import FolderEntity, TaskEntity
from ayon_server.entities import FolderEntity, TaskEntity, ProjectEntity
from ayon_server.lib.postgres import Postgres
from ayon_server.types import OPModel, Field

Expand Down Expand Up @@ -96,12 +96,12 @@ async def get_root_folder_id(
async def sync_folder(
addon,
user,
project_name,
project,
existing_folders,
entity_dict,
):
target_folder = await get_folder_by_kitsu_id(
project_name,
project.name,
entity_dict["id"],
existing_folders,
)
Expand All @@ -113,7 +113,7 @@ async def sync_folder(
else:
parent_id = await get_root_folder_id(
user=user,
project_name=project_name,
project_name=project.name,
kitsu_type="Assets",
kitsu_type_id="asset",
subfolder_id=entity_dict["entity_type_id"],
Expand All @@ -125,7 +125,7 @@ async def sync_folder(
if entity_dict.get("parent_id") is None:
parent_id = await get_root_folder_id(
user=user,
project_name=project_name,
project_name=project.name,
kitsu_type="Episodes",
kitsu_type_id="episode",
)
Expand All @@ -134,7 +134,7 @@ async def sync_folder(
parent_id = existing_folders[entity_dict["parent_id"]]
else:
parent_folder = await get_folder_by_kitsu_id(
project_name,
project.name,
entity_dict["parent_id"],
existing_folders,
)
Expand All @@ -144,7 +144,7 @@ async def sync_folder(
if entity_dict.get("parent_id") is None:
parent_id = await get_root_folder_id(
user=user,
project_name=project_name,
project_name=project.name,
kitsu_type="Sequences",
kitsu_type_id="sequence",
)
Expand All @@ -153,15 +153,15 @@ async def sync_folder(
parent_id = existing_folders[entity_dict["parent_id"]]
else:
parent_folder = await get_folder_by_kitsu_id(
project_name, entity_dict["parent_id"], existing_folders
project.name, entity_dict["parent_id"], existing_folders
)
parent_id = parent_folder.id

elif entity_dict["type"] == "Shot":
if entity_dict.get("parent_id") is None:
parent_id = await get_root_folder_id(
user=user,
project_name=project_name,
project_name=project.name,
kitsu_type="Shots",
kitsu_type_id="shot",
)
Expand All @@ -170,7 +170,7 @@ async def sync_folder(
parent_id = existing_folders[entity_dict["parent_id"]]
else:
parent_folder = await get_folder_by_kitsu_id(
project_name, entity_dict["parent_id"], existing_folders
project.name, entity_dict["parent_id"], existing_folders
)
parent_id = parent_folder.id

Expand All @@ -179,7 +179,7 @@ async def sync_folder(

logging.info(f"Creating {entity_dict['type']} {entity_dict['name']}")
target_folder = await create_folder(
project_name=project_name,
project_name=project.name,
attrib=parse_attrib(entity_dict.get("data", {})),
name=entity_dict["name"],
folder_type=entity_dict["type"],
Expand All @@ -188,7 +188,7 @@ async def sync_folder(
)

else:
folder = await FolderEntity.load(project_name, target_folder.id)
folder = await FolderEntity.load(project.name, target_folder.id)
changed = False
for key, value in parse_attrib(entity_dict.get("data", {})).items():
if getattr(folder.attrib, key) != value:
Expand All @@ -210,13 +210,13 @@ async def sync_folder(
async def sync_task(
addon,
user,
project_name,
project,
existing_tasks,
existing_folders,
entity_dict,
):
target_task = await get_task_by_kitsu_id(
project_name,
project.name,
entity_dict["id"],
existing_tasks,
)
Expand All @@ -227,13 +227,36 @@ async def sync_task(
parent_id = existing_folders[entity_dict["entity_id"]]
else:
parent_folder = await get_folder_by_kitsu_id(
project_name, entity_dict["entity_id"], existing_folders
project.name, entity_dict["entity_id"], existing_folders
)

if parent_folder is None:
parent_id = await get_root_folder_id(
user=user,
project_name=project.name,
kitsu_type="Edits",
kitsu_type_id="edits",
)
else:
parent_id = parent_folder.id

if entity_dict["task_type_name"] not in [
task_type["name"] for task_type in project.task_types
]:
logging.info(
f"Creating task type {entity_dict['task_type_name']} for {project.name}"
)
parent_id = parent_folder.id
project.task_types.append(
{
"name": entity_dict["task_type_name"],
"short_name": entity_dict["task_type_name"][:4],
}
)
await project.save()

logging.info(f"Creating {entity_dict['type']} {entity_dict['name']}")
target_task = await create_task(
project_name=project_name,
project_name=project.name,
folder_id=parent_id,
status=entity_dict["task_status_name"],
task_type=entity_dict["task_type_name"],
Expand All @@ -243,7 +266,7 @@ async def sync_task(
)

else:
task = await TaskEntity.load(project_name, target_task.id)
task = await TaskEntity.load(project.name, target_task.id)
changed = False
for key, value in parse_attrib(entity_dict.get("data", {})).items():
if getattr(task.attrib, key) != value:
Expand All @@ -262,7 +285,7 @@ async def push_entities(
payload: PushEntitiesRequestModel,
) -> None:
start_time = time.time()
project_name = payload.project_name
project = await ProjectEntity.load(payload.project_name)

# A mapping of kitsu entity ids to folder ids
# This object only exists during the request
Expand All @@ -281,7 +304,7 @@ async def push_entities(
await sync_folder(
addon,
user,
project_name,
project,
existing_folders,
entity_dict,
)
Expand All @@ -290,7 +313,7 @@ async def push_entities(
await sync_task(
addon,
user,
project_name,
project,
existing_tasks,
existing_folders,
entity_dict,
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1-dev1"
__version__ = "1.0.1"

0 comments on commit 6d95bf2

Please sign in to comment.