Skip to content

[project] for tvshow put main pack in episodes #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def generate_fixture_asset(
description="Description Tree",
asset_type_id=None,
project_id=None,
episode_id=None,
):
if asset_type_id is None:
asset_type_id = self.asset_type.id
Expand All @@ -361,9 +362,23 @@ def generate_fixture_asset(
description=description,
project_id=project_id,
entity_type_id=asset_type_id,
source_id=episode_id,
)
return self.asset

def generate_fixture_main_pack_episode(
self,
project_id,
name="MP",
):
self.main_pack_episode = Entity.create(
name=name,
project_id=project_id,
entity_type_id=self.episode_type.id,
is_main_pack=True,
)
return self.main_pack_episode

def generate_fixture_asset_character(
self, name="Rabbit", description="Main char"
):
Expand Down
7 changes: 5 additions & 2 deletions tests/export/test_casting_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def setUp(self):
self.generate_fixture_asset_types()

def test_import_casting(self):
project_id = str(self.project.id)
mp_id = self.generate_fixture_main_pack_episode(project_id).id
for name, asset_type_id in [
("Lake", self.asset_type_environment.id),
("Mine", self.asset_type_environment.id),
Expand All @@ -22,7 +24,9 @@ def test_import_casting(self):
("Victor", self.asset_type_character.id),
("John", self.asset_type_character.id),
]:
self.generate_fixture_asset(name, asset_type_id=asset_type_id)
self.generate_fixture_asset(
name, asset_type_id=asset_type_id, episode_id=mp_id
)
if name == "Lake":
self.asset_lake_id = self.asset.id
if name == "Mine":
Expand All @@ -37,7 +41,6 @@ def test_import_casting(self):
episode2_id = self.generate_fixture_episode("E02").id
self.generate_fixture_sequence("SEQ01")
self.generate_fixture_shot("SH01").id
project_id = str(self.project.id)

path = "/import/csv/projects/%s/casting" % project_id
self.upload_csv(path, "casting")
Expand Down
8 changes: 5 additions & 3 deletions tests/services/test_playlists_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ def test_get_playlist_for_episode(self):
self.project.id, True
)
self.assertEqual(len(playlists), 1)

self.generate_fixture_playlist("Test main pack", for_entity="asset")
mp_id = self.generate_fixture_main_pack_episode(self.project.id).id
self.generate_fixture_playlist(
"Test main pack", for_entity="asset", episode_id=mp_id
)
self.generate_fixture_playlist(
"Test all playlist", for_entity="asset", is_for_all=True
)
playlists = playlists_service.all_playlists_for_episode(
self.project.id, "main"
self.project.id, mp_id
)
self.assertEqual(len(playlists), 1)
playlists = playlists_service.all_playlists_for_episode(
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def check_create_permissions(self, playlist):

def update_data(self, data):
data = super().update_data(data)
if "episode_id" in data and data["episode_id"] in ["all", "main"]:
if "episode_id" in data and data["episode_id"] in ["all"]:
data["episode_id"] = None
if "task_type_id" in data and not fields.is_valid_id(
data["task_type_id"]
Expand Down
6 changes: 6 additions & 0 deletions zou/app/blueprints/crud/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def post_creation(self, project):
project_dict["first_episode_id"] = fields.serialize_value(
episode["id"]
)
episode = shots_service.create_episode(
project.id,
"MP",
created_by=persons_service.get_current_user()["id"],
is_main_pack=True,
)
user_service.clear_project_cache()
projects_service.clear_project_cache("")
return project_dict
Expand Down
61 changes: 1 addition & 60 deletions zou/app/blueprints/export/csv/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ def build_results(
is_shot_casting=False,
):
results = []
if episode_id == "main":
results = self.build_main_pack_results(project_id)
elif episode_id == "all":
if episode_id == "all":
results = self.build_episodes_results(project_id)
elif is_shot_casting:
results = self.build_shot_results(
Expand Down Expand Up @@ -291,7 +289,6 @@ def build_asset_results(
entity_link.label,
)
)
results += self.build_main_pack_results(project_id)
else:
query = query.add_columns(
ParentAssetType.name,
Expand Down Expand Up @@ -325,62 +322,6 @@ def build_asset_results(

return results

def build_main_pack_results(self, project_id):
results = []
ParentAsset = aliased(Entity, name="parent_asset")
ParentAssetType = aliased(EntityType, name="parent_asset_type")
Asset = aliased(Entity, name="asset")
AssetType = aliased(EntityType, name="asset_type")
shot_type = shots_service.get_shot_type()
episode_type = shots_service.get_episode_type()

query = (
EntityLink.query.join(
ParentAsset, EntityLink.entity_in_id == ParentAsset.id
)
.join(
ParentAssetType,
ParentAsset.entity_type_id == ParentAssetType.id,
)
.join(Asset, EntityLink.entity_out_id == Asset.id)
.join(AssetType, Asset.entity_type_id == AssetType.id)
.filter(ParentAsset.project_id == project_id)
.filter(ParentAsset.source_id == None)
.filter(ParentAssetType.id != shot_type["id"])
.filter(ParentAssetType.id != episode_type["id"])
)
query = query.add_columns(
ParentAssetType.name,
ParentAsset.name,
AssetType.name,
Asset.name,
).order_by(
ParentAssetType.name,
ParentAsset.name,
AssetType.name,
Asset.name,
)
for (
entity_link,
parent_asset_type_name,
parent_name,
asset_type_name,
asset_name,
) in query.all():
results.append(
(
"MP",
"",
parent_asset_type_name,
parent_name,
asset_type_name,
asset_name,
entity_link.nb_occurences,
entity_link.label,
)
)
return results

def build_episodes_results(self, project_id):
results = []
ParentAsset = aliased(Entity, name="parent_asset")
Expand Down
6 changes: 1 addition & 5 deletions zou/app/blueprints/playlists/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get(self, project_id, episode_id):
page = self.get_page()
sort_by = self.get_sort_by()
task_type_id = self.get_text_parameter("task_type_id")
if episode_id not in ["main", "all"]:
if episode_id not in ["all"]:
shots_service.get_episode(episode_id)
return playlists_service.all_playlists_for_episode(
project_id,
Expand Down Expand Up @@ -234,8 +234,6 @@ def get(self, playlist_id, build_job_id):
episode_name = episode["name"]
elif playlist["is_for_all"]:
episode_name = "all assets"
else:
episode_name = "main pack"
context_name += "_%s" % slugify.slugify(
episode_name, separator="_"
)
Expand Down Expand Up @@ -365,8 +363,6 @@ def get(self, playlist_id):
episode_name = episode["name"]
elif playlist["is_for_all"]:
episode_name = "all assets"
else:
episode_name = "main pack"
context_name += "_%s" % slugify.slugify(
episode_name, separator="_"
)
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/source/csv/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def import_row(self, row, project_id):
episode_id = None

if self.is_tv_show:
if episode_name not in [None, "MP"] + list(self.episodes.keys()):
if episode_name not in list(self.episodes.keys()):
self.episodes[episode_name] = shots_service.create_episode(
project_id, episode_name, created_by=self.current_user_id
)["id"]
Expand Down
2 changes: 0 additions & 2 deletions zou/app/blueprints/source/csv/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ def get_episode_key(self, episode):

def import_row(self, row, project_id):
asset_key = slugify(f"{row['Asset Type']}{row['Asset']}")
if row.get("Episode") in ["MP", None]:
row["Episode"] = ""
target_key = slugify(f"{row['Episode']}{row['Parent']}{row['Name']}")
occurences = 1
if len(row["Occurences"]) > 0:
Expand Down
4 changes: 2 additions & 2 deletions zou/app/blueprints/source/csv/task_type_estimations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def prepare_import(self, project_id, task_type_id, episode_id=None):
asset_types_map[asset_type["id"]] = slugify(asset_type["name"])

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

sequences_map = {}
criterions_sequences = {"project_id": project_id}
if episode_id is not None and episode_id not in ["main", "all"]:
if episode_id is not None and episode_id not in ["all"]:
criterions_sequences["parent_id"] = episode_id
sequences = shots_service.get_sequences(criterions_sequences)
for sequence in sequences:
Expand Down
3 changes: 3 additions & 0 deletions zou/app/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class Entity(db.Model, BaseMixin, SerializerMixin):

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

# specific to episodes
is_main_pack = db.Column(db.Boolean, default=False, nullable=False)

status = db.Column(
ChoiceType(ENTITY_STATUSES), default="running", nullable=False
)
Expand Down
43 changes: 38 additions & 5 deletions zou/app/services/assets_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
AssetNotFoundException,
AssetInstanceNotFoundException,
AssetTypeNotFoundException,
EpisodeNotFoundException,
)


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

if "episode_id" in criterions:
episode_id = criterions["episode_id"]
if episode_id == "main":
tasks_query = tasks_query.filter(Entity.source_id == None)
elif episode_id != "all":
if episode_id != "all":
tasks_query = tasks_query.outerjoin(
EntityLink, EntityLink.entity_out_id == Entity.id
)
Expand Down Expand Up @@ -250,7 +249,6 @@ def get_assets_and_tasks(criterions={}, with_episode_ids=False):
Episode.project_id == criterions["project_id"]
)
if "episode_id" in criterions and criterions["episode_id"] not in [
"main",
"all",
]:
episode_links_query = episode_links_query.filter(
Expand Down Expand Up @@ -586,6 +584,36 @@ def create_asset_types(asset_type_names):
return asset_types


def get_main_pack_raw(project_id):
"""
Get the main pack episode of a project.
"""
episode_type = shots_service.get_episode_type()
if episode_type is None:
episode_type = shots_service.get_episode_type()

try:
main_pack_episode = Entity.get_by(
entity_type_id=episode_type["id"],
is_main_pack=True,
project_id=project_id,
)
except StatementError:
raise EpisodeNotFoundException

if main_pack_episode is None:
raise EpisodeNotFoundException
return main_pack_episode


@cache.memoize_function(120)
def get_main_pack(project_id):
"""
Get the main pack episode of a project as a dictionnary.
"""
return get_main_pack_raw(project_id).serialize(obj_type="Episode")


def create_asset(
project_id,
asset_type_id,
Expand All @@ -603,6 +631,11 @@ def create_asset(
asset_type = get_asset_type_raw(asset_type_id)
if source_id is not None and len(source_id) < 36:
source_id = None

if project.production_type == "tvshow" and source_id is None:
main_pack = get_main_pack_raw(project_id)
source_id = main_pack.id

asset = Entity.create(
project_id=project_id,
entity_type_id=asset_type_id,
Expand Down Expand Up @@ -791,7 +824,7 @@ def get_shared_assets_used_in_project(project_id, episode_id=None):
.filter(Entity.project_id != project_id)
)

if episode_id is not None and episode_id not in ["main", "all"]:
if episode_id is not None and episode_id not in ["all"]:
assets = assets.filter(Sequence.parent_id == episode_id)

return Entity.serialize_list(assets.all(), obj_type="Asset")
2 changes: 0 additions & 2 deletions zou/app/services/breakdown_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def get_sequence_casting(sequence_id, project_id=None, episode_id=None):
are casting for given shot.
"""
castings = {}
if episode_id == "main":
return {}

Shot = aliased(Entity, name="shot")
Sequence = aliased(Entity, name="sequence")
Expand Down
11 changes: 1 addition & 10 deletions zou/app/services/playlists_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from flask_fs.errors import FileNotFound
from slugify import slugify
from sqlalchemy import or_

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

if episode_id == "main":
query = (
query.filter(Playlist.episode_id == None)
.filter(Playlist.project_id == project_id)
.filter(
or_(Playlist.is_for_all is None, Playlist.is_for_all == False)
)
)
elif episode_id == "all":
if episode_id == "all":
query = (
query.filter(Playlist.episode_id == None)
.filter(Playlist.project_id == project_id)
Expand Down
2 changes: 2 additions & 0 deletions zou/app/services/shots_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ def create_episode(
description="",
data={},
created_by=None,
is_main_pack=False,
):
"""
Create episode for given project.
Expand All @@ -951,6 +952,7 @@ def create_episode(
description=description,
data=data,
created_by=created_by,
is_main_pack=is_main_pack,
)
events.emit(
"episode:new", {"episode_id": episode.id}, project_id=project_id
Expand Down
Loading