示例#1
0
def remove_episode(episode_id, force=False):
    """
    Remove an episode and all related sequences and shots.
    """
    from zou.app.services import shots_service, assets_service

    episode = shots_service.get_episode_raw(episode_id)
    if force:
        for sequence in Entity.get_all_by(parent_id=episode_id):
            shots_service.remove_sequence(sequence.id, force=True)
        for asset in Entity.get_all_by(source_id=episode_id):
            assets_service.remove_asset(asset.id, force=True)
        Playlist.delete_all_by(episode_id=episode_id)
        ScheduleItem.delete_all_by(object_id=episode_id)
    try:
        episode.delete()
        events.emit(
            "episode:delete",
            {"episode_id": episode_id},
            project_id=str(episode.project_id),
        )
    except IntegrityError:
        raise ModelWithRelationsDeletionException(
            "Some data are still linked to this episode.")
    shots_service.clear_episode_cache(episode_id)
    return episode.serialize(obj_type="Episode")
示例#2
0
def all_playlists_for_episode(episode_id, for_client=False):
    """
    Return all playlists created for given episode.
    """
    result = []
    if for_client:
        playlists = Playlist.get_all_by(episode_id=episode_id, for_client=True)
    else:
        playlists = Playlist.get_all_by(episode_id=episode_id)
    for playlist in playlists:
        playlist_dict = build_playlist_dict(playlist)
        result.append(playlist_dict)
    return result
示例#3
0
 def generate_fixture_playlist(self):
     self.playlist = Playlist.create(name="Playlist 1",
                                     shots={},
                                     project_id=self.project.id,
                                     episode_id=self.episode.id)
     Playlist.create(name="Playlist 2",
                     shots={},
                     project_id=self.project_standard.id)
     self.playlist = Playlist.create(name="Playlist 3",
                                     shots={},
                                     project_id=self.project.id,
                                     episode_id=self.episode_2.id)
     return self.playlist.serialize()
示例#4
0
def all_playlists_for_episode(episode_id, for_client=False):
    """
    Return all playlists created for given project.
    """
    result = []
    if for_client:
        playlists = Playlist.get_all_by(episode_id=episode_id, for_client=True)
    else:
        playlists = Playlist.get_all_by(episode_id=episode_id)
    for playlist in playlists:
        playlist.shots = []
        playlist_dict = fields.serialize_value(playlist)
        del playlist_dict["shots"]
        result.append(playlist_dict)
    return result
示例#5
0
 def test_playlist(self):
     playlist_dict = {
         "build_jobs": [],
         "id": "36f6ab50-4e33-4da8-b853-2261d74fb64b",
         "created_at": "2019-08-06T11:11:02",
         "updated_at": "2019-08-06T13:11:02",
         "name": "2019-08-06 13:11:02 New playlist ",
         "shots": [],
         "project_id": str(self.project.id),
         "episode_id": str(self.episode.id),
         "type": "Playlist"
     }
     Playlist.create_from_import(playlist_dict)
     playlist = Playlist.get(playlist_dict["id"])
     self.assertEqual(playlist.name, playlist_dict["name"])
示例#6
0
def remove_episode(episode_id, force=False):
    """
    Remove an episode and all related sequences and shots.
    """
    episode = get_episode_raw(episode_id)
    if force:
        for sequence in Entity.get_all_by(parent_id=episode_id):
            remove_sequence(sequence.id, force=True)
        Playlist.delete_all_by(episode_id=episode_id)
        ScheduleItem.delete_all_by(object_id=episode_id)
    try:
        episode.delete()
    except IntegrityError:
        raise ModelWithRelationsDeletionException(
            "Some data are still linked to this episode.")
    return episode.serialize(obj_type="Episode")
示例#7
0
 def test_build_playlist_dict(self):
     playlist = Playlist.create(name="Playlist 1",
                                shots={},
                                project_id=self.project.id,
                                episode_id=self.episode.id)
     playlist_dict = playlists_service.build_playlist_dict(playlist)
     self.assertTrue("shots" not in playlist_dict)
     self.assertEqual(playlist_dict["for_entity"], "shot")
示例#8
0
 def generate_fixture_playlist(self,
                               name,
                               project_id=None,
                               episode_id=None,
                               for_entity="shot",
                               for_client=False,
                               is_for_all=False):
     if project_id is None:
         project_id = self.project.id
     self.playlist = Playlist.create(name=name,
                                     project_id=project_id,
                                     episode_id=episode_id,
                                     for_entity=for_entity,
                                     is_for_all=is_for_all,
                                     for_client=for_client,
                                     shots=[])
     return self.playlist.serialize()
示例#9
0
def get_playlist_with_preview_file_revisions(playlist_id):
    """
    Return given playlist. Shot list is augmented with all previews available
    for a given shot.
    """
    playlist = Playlist.get(playlist_id)

    if playlist is None:
        raise PlaylistNotFoundException()

    playlist_dict = playlist.serialize()

    if playlist_dict["shots"] is None:
        playlist_dict["shots"] = []

    for shot in playlist_dict["shots"]:
        try:
            preview_file = PreviewFile.get(shot["preview_file_id"])
            if preview_file is None or preview_file.extension != 'mp4':
                preview_file = PreviewFile.query \
                    .filter_by(task_id=preview_file.task_id) \
                    .filter_by(extension="mp4") \
                    .join(Task) \
                    .join(TaskType) \
                    .order_by(TaskType.priority.desc()) \
                    .order_by(TaskType.name) \
                    .order_by(PreviewFile.revision.desc()) \
                    .first()
            if preview_file is not None:
                shot["preview_file_id"] = str(preview_file.id)
                shot["extension"] = preview_file.extension
                shot["annotations"] = preview_file.annotations
                shot["task_id"] = fields.serialize_value(preview_file.task_id)
            else:
                del shot["preview_file_id"]
        except Exception as e:
            print(e)

        try:
            shot["preview_files"] = get_preview_files_for_shot(shot["shot_id"])
        except ShotNotFoundException:
            playlist_dict["shots"].remove(shot)
    return playlist_dict
示例#10
0
def get_playlist_with_preview_file_revisions(playlist_id):
    """
    Return given playlist. Shot list is augmented with all previews available
    for a given shot.
    """
    playlist = Playlist.get(playlist_id)

    if playlist is None:
        raise PlaylistNotFoundException()

    playlist_dict = playlist.serialize()

    playlist_dict["build_jobs"] = []
    for build_job in reversed(playlist.build_jobs):
        playlist_dict["build_jobs"].append(fields.serialize_dict({
          "id": build_job.id,
          "status": build_job.status,
          "created_at": build_job.created_at
        }))

    if playlist_dict["shots"] is None:
        playlist_dict["shots"] = []

    (
        playlist_dict,
        preview_file_map
    ) = set_preview_files_for_shots(playlist_dict)

    for shot in playlist_dict["shots"]:
        try:
            preview_file = preview_file_map.get(shot["preview_file_id"], None)
            if preview_file is not None:
                shot["preview_file_id"] = str(preview_file.id)
                shot["extension"] = preview_file.extension
                shot["annotations"] = preview_file.annotations
                shot["task_id"] = fields.serialize_value(preview_file.task_id)
            else:
                del shot["preview_file_id"]
        except Exception as e:
            print(e)

    return playlist_dict
示例#11
0
def get_playlist_with_preview_file_revisions(playlist_id):
    """
    Return given playlist. Shot list is augmented with all previews available
    for a given shot.
    """
    playlist = Playlist.get(playlist_id)

    if playlist is None:
        raise PlaylistNotFoundException()

    playlist_dict = playlist.serialize()

    if playlist_dict["shots"] is None:
        playlist_dict["shots"] = []

    for shot in playlist_dict["shots"]:
        shot["preview_files"] = get_preview_files_for_shot(
            shot["shot_id"]
        )
    return playlist_dict
示例#12
0
文件: base.py 项目: manuelrais/zou
 def generate_fixture_playlist(self, name, project_id=None):
     if project_id is None:
         project_id = self.project.id
     self.playlist = Playlist.create(name=name, project_id=project_id)
     return self.playlist.serialize()
示例#13
0
def all_playlists_for_project(project_id):
    """
    Return all playlists created for given project.
    """
    return fields.serialize_value(Playlist.get_all_by(project_id=project_id))