Skip to content

Commit

Permalink
Merge pull request #340 from EvanBldy/master
Browse files Browse the repository at this point in the history
various improvements
  • Loading branch information
EvanBldy authored Oct 10, 2024
2 parents ef65d5b + 97e046a commit da2a685
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 67 deletions.
5 changes: 4 additions & 1 deletion gazu/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def update_episode_casting(project, episode, casting, client=default):
"""
episode = normalize_model_parameter(episode)
project = normalize_model_parameter(project)
path = "data/projects/%s/entities/%s/casting" % (project["id"], episode["id"])
path = "data/projects/%s/entities/%s/casting" % (
project["id"],
episode["id"],
)
return raw.put(path, casting, client=client)


Expand Down
32 changes: 11 additions & 21 deletions gazu/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,12 @@ def get_entity_preview_files(entity, client=default):
entity = normalize_model_parameter(entity)
return raw.get(
"data/playlists/entities/%s/preview-files" % entity["id"],
client=client
client=client,
)


def add_entity_to_playlist(
playlist,
entity,
preview_file=None,
persist=True,
client=default
playlist, entity, preview_file=None, persist=True, client=default
):
"""
Add an entity to the playlist, use the last uploaded preview as revision
Expand All @@ -197,25 +193,23 @@ def add_entity_to_playlist(
for task_type_id in preview_files.keys():
task_type_files = preview_files[task_type_id]
first_file = task_type_files[0]
if preview_file is None or \
preview_file["created_at"] < first_file["created_at"]:
if (
preview_file is None
or preview_file["created_at"] < first_file["created_at"]
):
preview_file = first_file

preview_file = normalize_model_parameter(preview_file)
playlist["shots"].append({
"entity_id": entity["id"],
"preview_file_id": preview_file["id"]
})
playlist["shots"].append(
{"entity_id": entity["id"], "preview_file_id": preview_file["id"]}
)
if persist:
update_playlist(playlist, client=client)
return playlist


def remove_entity_from_playlist(
playlist,
entity,
persist=True,
client=default
playlist, entity, persist=True, client=default
):
"""
Remove all occurences of a given entity from a playlist.
Expand All @@ -239,11 +233,7 @@ def remove_entity_from_playlist(


def update_entity_preview(
playlist,
entity,
preview_file,
persist=True,
client=default
playlist, entity, preview_file, persist=True, client=default
):
"""
Remove all occurences of a given entity from a playlist.
Expand Down
26 changes: 3 additions & 23 deletions gazu/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,7 @@ def all_tasks_for_task_status(project, task_type, task_status, client=default):


@cache
def all_tasks_for_task_type(
project,
task_type,
episode=None,
client=default
):
def all_tasks_for_task_type(project, task_type, episode=None, client=default):
"""
Args:
project (str / dict): The project dict or the project ID.
Expand Down Expand Up @@ -532,18 +527,6 @@ def get_task_status_by_name(name, client=default):
return raw.fetch_first("task-status", {"name": name}, client=client)


@cache
def get_default_task_status(client=default):
"""
Args:
name (str / dict): The name of claimed task status.
Returns:
dict: Task status matching given name.
"""
return raw.fetch_first("task-status", {"is_default": True}, client=client)


@cache
def get_task_status_by_short_name(task_status_short_name, client=default):
"""
Expand Down Expand Up @@ -661,7 +644,7 @@ def new_task(
entity = normalize_model_parameter(entity)
task_type = normalize_model_parameter(task_type)
if task_status is None:
task_status = get_default_task_status()
task_status = get_default_task_status(client=client)

data = {
"project_id": entity["project_id"],
Expand Down Expand Up @@ -1267,10 +1250,7 @@ def get_task_url(task, client=default):


def all_tasks_for_project(
project,
task_type=None,
episode=None,
client=default
project, task_type=None, episode=None, client=default
):
"""
Args:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ test =

lint =
autoflake==2.3.1; python_version >= '3.8'
black==24.8.0; python_version >= '3.8'
pre-commit==3.8.0; python_version >= '3.9'
black==24.10.0; python_version >= '3.9'
pre-commit==4.0.1; python_version >= '3.9'

[bdist_wheel]
universal = 1
4 changes: 3 additions & 1 deletion tests/test_casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def test_update_episode_casting(self):
mock.put(gazu.client.get_full_url(path), text=json.dumps(casting))
episode = {"id": fakeid("episode-01")}
project = {"id": fakeid("project-01")}
casting = gazu.casting.update_episode_casting(project, episode, casting)
casting = gazu.casting.update_episode_casting(
project, episode, casting
)
self.assertEqual(casting[0]["asset_id"], fakeid("asset-1"))

def test_get_asset_type_casting(self):
Expand Down
46 changes: 27 additions & 19 deletions tests/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def test_add_entity_to_playlist(self):
)
mock.get(
gazu.client.get_full_url(
"data/playlists/entities/%s/preview-files" % fakeid("shot-1")
"data/playlists/entities/%s/preview-files"
% fakeid("shot-1")
),
text=json.dumps(
{fakeid("task-type-1"): [{"id": fakeid("preview-1")}]}
Expand All @@ -188,26 +189,33 @@ def test_add_entity_to_playlist(self):
playlist = {
"id": fakeid("playlist-1"),
"name": "name_changed",
"shots": []
}
shot = {
"id": fakeid("shot-1"),
"name": "SH01"
"shots": [],
}
shot = {"id": fakeid("shot-1"), "name": "SH01"}
playlist = gazu.playlist.add_entity_to_playlist(playlist, shot)
self.assertEqual(playlist["id"], fakeid("playlist-1"))
self.assertEqual(playlist["shots"], [{
"entity_id": fakeid("shot-1"),
"preview_file_id": fakeid("preview-1")
}])
self.assertEqual(
playlist["shots"],
[
{
"entity_id": fakeid("shot-1"),
"preview_file_id": fakeid("preview-1"),
}
],
)
playlist = gazu.playlist.update_entity_preview(
playlist,
shot,
fakeid("preview-2")
)
self.assertEqual(playlist["shots"], [{
"entity_id": fakeid("shot-1"),
"preview_file_id": fakeid("preview-2")
}])
playlist = gazu.playlist.remove_entity_from_playlist(playlist, shot)
playlist, shot, fakeid("preview-2")
)
self.assertEqual(
playlist["shots"],
[
{
"entity_id": fakeid("shot-1"),
"preview_file_id": fakeid("preview-2"),
}
],
)
playlist = gazu.playlist.remove_entity_from_playlist(
playlist, shot
)
self.assertEqual(playlist["shots"], [])

0 comments on commit da2a685

Please sign in to comment.