Skip to content

Commit da51ed7

Browse files
committed
[project] for tvshow put main pack in episodes
1 parent 48d00f9 commit da51ed7

17 files changed

+384
-104
lines changed

tests/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def generate_fixture_asset(
349349
description="Description Tree",
350350
asset_type_id=None,
351351
project_id=None,
352+
episode_id=None,
352353
):
353354
if asset_type_id is None:
354355
asset_type_id = self.asset_type.id
@@ -361,9 +362,23 @@ def generate_fixture_asset(
361362
description=description,
362363
project_id=project_id,
363364
entity_type_id=asset_type_id,
365+
source_id=episode_id,
364366
)
365367
return self.asset
366368

369+
def generate_fixture_main_pack_episode(
370+
self,
371+
project_id,
372+
name="MP",
373+
):
374+
self.main_pack_episode = Entity.create(
375+
name=name,
376+
project_id=project_id,
377+
entity_type_id=self.episode_type.id,
378+
is_main_pack=True,
379+
)
380+
return self.main_pack_episode
381+
367382
def generate_fixture_asset_character(
368383
self, name="Rabbit", description="Main char"
369384
):

tests/export/test_casting_to_csv.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def setUp(self):
1111
self.generate_fixture_asset_types()
1212

1313
def test_import_casting(self):
14+
project_id = str(self.project.id)
15+
mp_id = self.generate_fixture_main_pack_episode(project_id).id
1416
for name, asset_type_id in [
1517
("Lake", self.asset_type_environment.id),
1618
("Mine", self.asset_type_environment.id),
@@ -22,7 +24,9 @@ def test_import_casting(self):
2224
("Victor", self.asset_type_character.id),
2325
("John", self.asset_type_character.id),
2426
]:
25-
self.generate_fixture_asset(name, asset_type_id=asset_type_id)
27+
self.generate_fixture_asset(
28+
name, asset_type_id=asset_type_id, episode_id=mp_id
29+
)
2630
if name == "Lake":
2731
self.asset_lake_id = self.asset.id
2832
if name == "Mine":
@@ -37,7 +41,6 @@ def test_import_casting(self):
3741
episode2_id = self.generate_fixture_episode("E02").id
3842
self.generate_fixture_sequence("SEQ01")
3943
self.generate_fixture_shot("SH01").id
40-
project_id = str(self.project.id)
4144

4245
path = "/import/csv/projects/%s/casting" % project_id
4346
self.upload_csv(path, "casting")

tests/services/test_playlists_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ def test_get_playlist_for_episode(self):
8686
self.project.id, True
8787
)
8888
self.assertEqual(len(playlists), 1)
89-
90-
self.generate_fixture_playlist("Test main pack", for_entity="asset")
89+
mp_id = self.generate_fixture_main_pack_episode(self.project.id).id
90+
self.generate_fixture_playlist(
91+
"Test main pack", for_entity="asset", episode_id=mp_id
92+
)
9193
self.generate_fixture_playlist(
9294
"Test all playlist", for_entity="asset", is_for_all=True
9395
)
9496
playlists = playlists_service.all_playlists_for_episode(
95-
self.project.id, "main"
97+
self.project.id, mp_id
9698
)
9799
self.assertEqual(len(playlists), 1)
98100
playlists = playlists_service.all_playlists_for_episode(

zou/app/blueprints/crud/playlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def check_create_permissions(self, playlist):
1717

1818
def update_data(self, data):
1919
data = super().update_data(data)
20-
if "episode_id" in data and data["episode_id"] in ["all", "main"]:
20+
if "episode_id" in data and data["episode_id"] in ["all"]:
2121
data["episode_id"] = None
2222
if "task_type_id" in data and not fields.is_valid_id(
2323
data["task_type_id"]

zou/app/blueprints/crud/project.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ def post_creation(self, project):
8787
project_dict["first_episode_id"] = fields.serialize_value(
8888
episode["id"]
8989
)
90+
episode = shots_service.create_episode(
91+
project.id,
92+
"MP",
93+
created_by=persons_service.get_current_user()["id"],
94+
is_main_pack=True,
95+
)
9096
user_service.clear_project_cache()
9197
projects_service.clear_project_cache("")
9298
return project_dict

zou/app/blueprints/export/csv/casting.py

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ def build_results(
128128
is_shot_casting=False,
129129
):
130130
results = []
131-
if episode_id == "main":
132-
results = self.build_main_pack_results(project_id)
133-
elif episode_id == "all":
131+
if episode_id == "all":
134132
results = self.build_episodes_results(project_id)
135133
elif is_shot_casting:
136134
results = self.build_shot_results(
@@ -291,7 +289,6 @@ def build_asset_results(
291289
entity_link.label,
292290
)
293291
)
294-
results += self.build_main_pack_results(project_id)
295292
else:
296293
query = query.add_columns(
297294
ParentAssetType.name,
@@ -325,62 +322,6 @@ def build_asset_results(
325322

326323
return results
327324

328-
def build_main_pack_results(self, project_id):
329-
results = []
330-
ParentAsset = aliased(Entity, name="parent_asset")
331-
ParentAssetType = aliased(EntityType, name="parent_asset_type")
332-
Asset = aliased(Entity, name="asset")
333-
AssetType = aliased(EntityType, name="asset_type")
334-
shot_type = shots_service.get_shot_type()
335-
episode_type = shots_service.get_episode_type()
336-
337-
query = (
338-
EntityLink.query.join(
339-
ParentAsset, EntityLink.entity_in_id == ParentAsset.id
340-
)
341-
.join(
342-
ParentAssetType,
343-
ParentAsset.entity_type_id == ParentAssetType.id,
344-
)
345-
.join(Asset, EntityLink.entity_out_id == Asset.id)
346-
.join(AssetType, Asset.entity_type_id == AssetType.id)
347-
.filter(ParentAsset.project_id == project_id)
348-
.filter(ParentAsset.source_id == None)
349-
.filter(ParentAssetType.id != shot_type["id"])
350-
.filter(ParentAssetType.id != episode_type["id"])
351-
)
352-
query = query.add_columns(
353-
ParentAssetType.name,
354-
ParentAsset.name,
355-
AssetType.name,
356-
Asset.name,
357-
).order_by(
358-
ParentAssetType.name,
359-
ParentAsset.name,
360-
AssetType.name,
361-
Asset.name,
362-
)
363-
for (
364-
entity_link,
365-
parent_asset_type_name,
366-
parent_name,
367-
asset_type_name,
368-
asset_name,
369-
) in query.all():
370-
results.append(
371-
(
372-
"MP",
373-
"",
374-
parent_asset_type_name,
375-
parent_name,
376-
asset_type_name,
377-
asset_name,
378-
entity_link.nb_occurences,
379-
entity_link.label,
380-
)
381-
)
382-
return results
383-
384325
def build_episodes_results(self, project_id):
385326
results = []
386327
ParentAsset = aliased(Entity, name="parent_asset")

zou/app/blueprints/playlists/resources.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get(self, project_id, episode_id):
9696
page = self.get_page()
9797
sort_by = self.get_sort_by()
9898
task_type_id = self.get_text_parameter("task_type_id")
99-
if episode_id not in ["main", "all"]:
99+
if episode_id not in ["all"]:
100100
shots_service.get_episode(episode_id)
101101
return playlists_service.all_playlists_for_episode(
102102
project_id,
@@ -234,8 +234,6 @@ def get(self, playlist_id, build_job_id):
234234
episode_name = episode["name"]
235235
elif playlist["is_for_all"]:
236236
episode_name = "all assets"
237-
else:
238-
episode_name = "main pack"
239237
context_name += "_%s" % slugify.slugify(
240238
episode_name, separator="_"
241239
)
@@ -365,8 +363,6 @@ def get(self, playlist_id):
365363
episode_name = episode["name"]
366364
elif playlist["is_for_all"]:
367365
episode_name = "all assets"
368-
else:
369-
episode_name = "main pack"
370366
context_name += "_%s" % slugify.slugify(
371367
episode_name, separator="_"
372368
)

zou/app/blueprints/source/csv/assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def import_row(self, row, project_id):
165165
episode_id = None
166166

167167
if self.is_tv_show:
168-
if episode_name not in [None, "MP"] + list(self.episodes.keys()):
168+
if episode_name not in list(self.episodes.keys()):
169169
self.episodes[episode_name] = shots_service.create_episode(
170170
project_id, episode_name, created_by=self.current_user_id
171171
)["id"]

zou/app/blueprints/source/csv/casting.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def get_episode_key(self, episode):
9595

9696
def import_row(self, row, project_id):
9797
asset_key = slugify(f"{row['Asset Type']}{row['Asset']}")
98-
if row.get("Episode") in ["MP", None]:
99-
row["Episode"] = ""
10098
target_key = slugify(f"{row['Episode']}{row['Parent']}{row['Name']}")
10199
occurences = 1
102100
if len(row["Occurences"]) > 0:

zou/app/blueprints/source/csv/task_type_estimations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def prepare_import(self, project_id, task_type_id, episode_id=None):
6060
asset_types_map[asset_type["id"]] = slugify(asset_type["name"])
6161

6262
criterions_assets = {"project_id": project_id}
63-
if episode_id is not None and episode_id not in ["main", "all"]:
63+
if episode_id is not None and episode_id not in ["all"]:
6464
criterions_assets["source_id"] = episode_id
6565
assets = assets_service.get_assets(criterions_assets)
6666
for asset in assets:
@@ -72,7 +72,7 @@ def prepare_import(self, project_id, task_type_id, episode_id=None):
7272

7373
sequences_map = {}
7474
criterions_sequences = {"project_id": project_id}
75-
if episode_id is not None and episode_id not in ["main", "all"]:
75+
if episode_id is not None and episode_id not in ["all"]:
7676
criterions_sequences["parent_id"] = episode_id
7777
sequences = shots_service.get_sequences(criterions_sequences)
7878
for sequence in sequences:

zou/app/models/entity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class Entity(db.Model, BaseMixin, SerializerMixin):
102102

103103
is_shared = db.Column(db.Boolean, default=False, nullable=False)
104104

105+
# specific to episodes
106+
is_main_pack = db.Column(db.Boolean, default=False, nullable=False)
107+
105108
status = db.Column(
106109
ChoiceType(ENTITY_STATUSES), default="running", nullable=False
107110
)

zou/app/services/assets_service.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
AssetNotFoundException,
3636
AssetInstanceNotFoundException,
3737
AssetTypeNotFoundException,
38+
EpisodeNotFoundException,
3839
)
3940

4041

@@ -217,9 +218,7 @@ def get_assets_and_tasks(criterions={}, with_episode_ids=False):
217218

218219
if "episode_id" in criterions:
219220
episode_id = criterions["episode_id"]
220-
if episode_id == "main":
221-
tasks_query = tasks_query.filter(Entity.source_id == None)
222-
elif episode_id != "all":
221+
if episode_id != "all":
223222
tasks_query = tasks_query.outerjoin(
224223
EntityLink, EntityLink.entity_out_id == Entity.id
225224
)
@@ -250,7 +249,6 @@ def get_assets_and_tasks(criterions={}, with_episode_ids=False):
250249
Episode.project_id == criterions["project_id"]
251250
)
252251
if "episode_id" in criterions and criterions["episode_id"] not in [
253-
"main",
254252
"all",
255253
]:
256254
episode_links_query = episode_links_query.filter(
@@ -586,6 +584,36 @@ def create_asset_types(asset_type_names):
586584
return asset_types
587585

588586

587+
def get_main_pack_raw(project_id):
588+
"""
589+
Get the main pack episode of a project.
590+
"""
591+
episode_type = shots_service.get_episode_type()
592+
if episode_type is None:
593+
episode_type = shots_service.get_episode_type()
594+
595+
try:
596+
main_pack_episode = Entity.get_by(
597+
entity_type_id=episode_type["id"],
598+
is_main_pack=True,
599+
project_id=project_id,
600+
)
601+
except StatementError:
602+
raise EpisodeNotFoundException
603+
604+
if main_pack_episode is None:
605+
raise EpisodeNotFoundException
606+
return main_pack_episode
607+
608+
609+
@cache.memoize_function(120)
610+
def get_main_pack(project_id):
611+
"""
612+
Get the main pack episode of a project as a dictionnary.
613+
"""
614+
return get_main_pack_raw(project_id).serialize(obj_type="Episode")
615+
616+
589617
def create_asset(
590618
project_id,
591619
asset_type_id,
@@ -603,6 +631,11 @@ def create_asset(
603631
asset_type = get_asset_type_raw(asset_type_id)
604632
if source_id is not None and len(source_id) < 36:
605633
source_id = None
634+
635+
if project.production_type == "tvshow" and source_id is None:
636+
main_pack = get_main_pack_raw(project_id)
637+
source_id = main_pack.id
638+
606639
asset = Entity.create(
607640
project_id=project_id,
608641
entity_type_id=asset_type_id,
@@ -791,7 +824,7 @@ def get_shared_assets_used_in_project(project_id, episode_id=None):
791824
.filter(Entity.project_id != project_id)
792825
)
793826

794-
if episode_id is not None and episode_id not in ["main", "all"]:
827+
if episode_id is not None and episode_id not in ["all"]:
795828
assets = assets.filter(Sequence.parent_id == episode_id)
796829

797830
return Entity.serialize_list(assets.all(), obj_type="Asset")

zou/app/services/breakdown_service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ def get_sequence_casting(sequence_id, project_id=None, episode_id=None):
148148
are casting for given shot.
149149
"""
150150
castings = {}
151-
if episode_id == "main":
152-
return {}
153151

154152
Shot = aliased(Entity, name="shot")
155153
Sequence = aliased(Entity, name="sequence")

zou/app/services/playlists_service.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from flask_fs.errors import FileNotFound
1414
from slugify import slugify
15-
from sqlalchemy import or_
1615

1716
from zou.app import config
1817
from zou.app.stores import file_store
@@ -97,15 +96,7 @@ def all_playlists_for_episode(
9796
if task_type_id is not None and len(task_type_id) > 0:
9897
query = query.filter(Playlist.task_type_id == task_type_id)
9998

100-
if episode_id == "main":
101-
query = (
102-
query.filter(Playlist.episode_id == None)
103-
.filter(Playlist.project_id == project_id)
104-
.filter(
105-
or_(Playlist.is_for_all is None, Playlist.is_for_all == False)
106-
)
107-
)
108-
elif episode_id == "all":
99+
if episode_id == "all":
109100
query = (
110101
query.filter(Playlist.episode_id == None)
111102
.filter(Playlist.project_id == project_id)

zou/app/services/shots_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ def create_episode(
932932
description="",
933933
data={},
934934
created_by=None,
935+
is_main_pack=False,
935936
):
936937
"""
937938
Create episode for given project.
@@ -951,6 +952,7 @@ def create_episode(
951952
description=description,
952953
data=data,
953954
created_by=created_by,
955+
is_main_pack=is_main_pack,
954956
)
955957
events.emit(
956958
"episode:new", {"episode_id": episode.id}, project_id=project_id

0 commit comments

Comments
 (0)