コード例 #1
0
def remove_metadata_descriptor(metadata_descriptor_id):
    """
    Delete metadata descriptor and related informations.
    """
    descriptor = get_metadata_descriptor_raw(metadata_descriptor_id)
    entities = Entity.get_all_by(project_id=descriptor.project_id)
    for entity in entities:
        metadata = fields.serialize_value(entity.data)
        if metadata is not None:
            metadata.pop(descriptor.field_name, None)
            entity.update({"data": metadata})
    try:
        descriptor.delete()
    except ObjectDeletedError:
        pass
    events.emit(
        "metadata-descriptor:delete",
        {"metadata_descriptor_id": str(descriptor.id)},
        project_id=descriptor.project_id,
    )
    clear_project_cache(str(descriptor.project_id))
    return descriptor.serialize()
コード例 #2
0
def update_metadata_descriptor(metadata_descriptor_id, changes):
    """
    Update metadata descriptor information for given id.
    """
    descriptor = get_metadata_descriptor_raw(metadata_descriptor_id)
    entities = Entity.get_all_by(project_id=descriptor.project_id)
    if "name" in changes and len(changes["name"]) > 0:
        changes["field_name"] = slugify.slugify(changes["name"])
        for entity in entities:
            metadata = fields.serialize_value(entity.data) or {}
            value = metadata.pop(descriptor.field_name, None)
            if value is not None:
                metadata[changes["field_name"]] = value
                entity.update({"data": metadata})
    descriptor.update(changes)
    events.emit(
        "metadata-descriptor:update",
        {"metadata_descriptor_id": str(descriptor.id)},
        project_id=descriptor.project_id,
    )
    clear_project_cache(str(descriptor.project_id))
    return descriptor.serialize()
コード例 #3
0
ファイル: test_utils.py プロジェクト: mathbou/zou
 def test_serialize_value(self):
     now = datetime.datetime.now()
     self.assertEqual(
         now.replace(microsecond=0).isoformat(),
         fields.serialize_value(now))
     unique_id = uuid.uuid4()
     self.assertEqual(str(unique_id), fields.serialize_value(unique_id))
     self.assertEqual(
         {"now": now.replace(microsecond=0).isoformat()},
         fields.serialize_value({"now": now}),
     )
     self.assertEqual("Europe/Paris",
                      fields.serialize_value(timezone("Europe/Paris")))
     self.assertEqual(
         "Europe/Brussels",
         fields.serialize_value(timezone("Europe/Brussels")),
     )
     self.assertEqual("en_US", fields.serialize_value(Locale("en_US")))
コード例 #4
0
def get_person_tasks(person_id, projects, is_done=None):
    """
    Retrieve all tasks for given person and projects.
    """
    person = Person.get(person_id)
    project_ids = [project["id"] for project in projects]

    Sequence = aliased(Entity, name="sequence")
    Episode = aliased(Entity, name="episode")
    query = (
        Task.query.join(Project, TaskType, TaskStatus)
        .join(Entity, Entity.id == Task.entity_id)
        .join(EntityType, EntityType.id == Entity.entity_type_id)
        .outerjoin(Sequence, Sequence.id == Entity.parent_id)
        .outerjoin(Episode, Episode.id == Sequence.parent_id)
        .filter(Task.assignees.contains(person))
        .filter(Project.id.in_(project_ids))
        .add_columns(
            Project.name,
            Project.has_avatar,
            Entity.id,
            Entity.name,
            Entity.description,
            Entity.preview_file_id,
            Entity.source_id,
            EntityType.name,
            Sequence.name,
            Episode.id,
            Episode.name,
            TaskType.name,
            TaskStatus.name,
            TaskType.color,
            TaskStatus.color,
            TaskStatus.short_name,
        )
    )

    if is_done:
        query = query.filter(TaskStatus.is_done == True).order_by(
            Task.end_date.desc(), TaskType.name, Entity.name
        )
    else:
        query = query.filter(TaskStatus.is_done == False)

    tasks = []
    for (
        task,
        project_name,
        project_has_avatar,
        entity_id,
        entity_name,
        entity_description,
        entity_preview_file_id,
        entity_source_id,
        entity_type_name,
        sequence_name,
        episode_id,
        episode_name,
        task_type_name,
        task_status_name,
        task_type_color,
        task_status_color,
        task_status_short_name,
    ) in query.all():
        if entity_preview_file_id is None:
            entity_preview_file_id = ""

        if entity_source_id is None:
            entity_source_id = ""

        if episode_id is None:
            episode_id = entity_source_id

        task_dict = task.serialize(relations=True)
        task_dict.update(
            {
                "project_name": project_name,
                "project_id": str(task.project_id),
                "project_has_avatar": project_has_avatar,
                "entity_id": str(entity_id),
                "entity_name": entity_name,
                "entity_description": entity_description,
                "entity_preview_file_id": str(entity_preview_file_id),
                "entity_source_id": str(entity_source_id),
                "entity_type_name": entity_type_name,
                "sequence_name": sequence_name,
                "episode_id": str(episode_id),
                "episode_name": episode_name,
                "task_estimation": task.estimation,
                "task_duration": task.duration,
                "task_due_date": fields.serialize_value(task.due_date),
                "task_type_name": task_type_name,
                "task_status_name": task_status_name,
                "task_type_color": task_type_color,
                "task_status_color": task_status_color,
                "task_status_short_name": task_status_short_name,
            }
        )
        tasks.append(task_dict)

    task_ids = [task["id"] for task in tasks]

    task_comment_map = {}
    comments = (
        Comment.query.filter(Comment.object_id.in_(task_ids))
        .join(Person)
        .filter(Person.role != "client")
        .order_by(Comment.object_id, Comment.created_at)
        .all()
    )

    task_id = None
    for comment in comments:
        if comment.object_id != task_id:
            task_id = fields.serialize_value(comment.object_id)
            task_comment_map[task_id] = {
                "text": comment.text,
                "date": fields.serialize_value(comment.created_at),
                "person_id": fields.serialize_value(comment.person_id),
            }
    for task in tasks:
        if task["id"] in task_comment_map:
            task["last_comment"] = task_comment_map[task["id"]]
        else:
            task["last_comment"] = {}

    return tasks
コード例 #5
0
 def get(self, project_id):
     user_service.check_project_access(project_id)
     project = projects_service.get_project()
     return fields.serialize_value(project.team)
コード例 #6
0
def get_assets_and_tasks(criterions={}, page=1):
    """
    Get all assets for given criterions with related tasks for each asset.
    """
    asset_map = {}
    task_map = {}

    query = Entity.query \
        .filter(build_asset_type_filter()) \
        .join(EntityType) \
        .outerjoin(Task) \
        .outerjoin(assignees_table) \
        .add_columns(
            EntityType.name,
            Task.id,
            Task.task_type_id,
            Task.task_status_id,
            Task.priority,
            assignees_table.columns.person
        ) \
        .order_by(
            EntityType.name,
            Entity.name
        )

    if "project_id" in criterions:
        query = query.filter(Entity.project_id == criterions["project_id"])

    for (asset, entity_type_name, task_id, task_type_id, task_status_id,
         task_priority, person_id) in query.all():

        if asset.id not in asset_map:
            asset_map[asset.id] = {
                "id": str(asset.id),
                "name": asset.name,
                "preview_file_id": str(asset.preview_file_id or ""),
                "description": asset.description,
                "asset_type_name": entity_type_name,
                "asset_type_id": str(asset.entity_type_id),
                "canceled": asset.canceled,
                "data": fields.serialize_value(asset.data),
                "tasks": []
            }

        if task_id is not None:
            if task_id not in task_map:
                task_dict = {
                    "id": str(task_id),
                    "entity_id": str(asset.id),
                    "task_status_id": str(task_status_id),
                    "task_type_id": str(task_type_id),
                    "priority": task_priority or 0,
                    "assignees": []
                }
                task_map[task_id] = task_dict
                asset_dict = asset_map[asset.id]
                asset_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(asset_map.values())
コード例 #7
0
def set_preview_files_for_entities(playlist_dict):
    """
    Retrieve all preview files related to entities listed in given playlist.
    Add to each entity a dict with task as keys and preview list as values.
    """
    entity_ids = []
    for entity in playlist_dict["shots"]:
        if "id" not in entity:
            entity_id = entity.get("shot_id", entity.get("entity_id", None))
            if entity_id is not None:
                entity_ids.append(entity_id)
                entity["id"] = entity_id
        else:
            entity_ids.append(entity["id"])
    previews = {}
    preview_file_map = {}

    preview_files = (PreviewFile.query.join(Task).join(TaskType).filter(
        Task.entity_id.in_(entity_ids)).order_by(
            TaskType.priority.desc()).order_by(TaskType.name).order_by(
                PreviewFile.revision.desc()).order_by(
                    PreviewFile.created_at).add_column(
                        Task.task_type_id).add_column(Task.entity_id).all())

    is_pictures = False
    for (preview_file, task_type_id, entity_id) in preview_files:
        entity_id = str(entity_id)
        task_type_id = str(task_type_id)
        if entity_id not in previews:
            previews[entity_id] = {}

        if task_type_id not in previews[entity_id]:
            previews[entity_id][task_type_id] = []

        if preview_file.extension == "png":
            is_pictures = True

        task_id = str(preview_file.task_id)
        preview_file_id = str(preview_file.id)

        light_preview_file = {
            "id": preview_file_id,
            "revision": preview_file.revision,
            "extension": preview_file.extension,
            "status": str(preview_file.status),
            "annotations": preview_file.annotations,
            "created_at": fields.serialize_value(preview_file.created_at),
            "task_id": task_id,
        }  # Do not add too much field to avoid building too big responses
        previews[entity_id][task_type_id].append(light_preview_file)
        preview_file_map[preview_file_id] = light_preview_file

    if is_pictures:
        for entity_id in previews.keys():
            for task_type_id in previews[entity_id].keys():
                previews[entity_id][task_type_id] = mix_preview_file_revisions(
                    previews[entity_id][task_type_id])

    for entity in playlist_dict["shots"]:
        if str(entity["id"]) in previews:
            entity["preview_files"] = previews[str(entity["id"])]
        else:
            entity["preview_files"] = []

    return (fields.serialize_value(playlist_dict), preview_file_map)
コード例 #8
0
 def delete(self, project_id, person_id):
     user_service.check_manager_project_access(project_id)
     project = projects_service.remove_team_member(project_id, person_id)
     return fields.serialize_value(project), 204
コード例 #9
0
def get_assets_and_tasks(criterions={}, page=1):
    """
    Get all assets for given criterions with related tasks for each asset.
    """
    asset_map = {}
    task_map = {}

    query = (
        Entity.query.filter(build_asset_type_filter())
        .join(EntityType)
        .outerjoin(Task)
        .outerjoin(assignees_table)
        .add_columns(
            EntityType.name,
            Task.id,
            Task.task_type_id,
            Task.task_status_id,
            Task.priority,
            Task.estimation,
            Task.duration,
            Task.retake_count,
            Task.real_start_date,
            Task.end_date,
            Task.start_date,
            Task.due_date,
            Task.last_comment_date,
            assignees_table.columns.person,
        )
        .order_by(EntityType.name, Entity.name)
    )

    if "id" in criterions:
        query = query.filter(Entity.id == criterions["id"])

    if "project_id" in criterions:
        query = query.filter(Entity.project_id == criterions["project_id"])

    if "episode_id" in criterions:
        if criterions["episode_id"] == "main":
            query = query.filter(Entity.source_id == None)
        elif criterions["episode_id"] != "all":
            query = query.filter(Entity.source_id == criterions["episode_id"])

    for (
        asset,
        entity_type_name,
        task_id,
        task_type_id,
        task_status_id,
        task_priority,
        task_estimation,
        task_duration,
        task_retake_count,
        task_real_start_date,
        task_end_date,
        task_start_date,
        task_due_date,
        task_last_comment_date,
        person_id,
    ) in query.all():

        if asset.source_id is None:
            source_id = ""
        else:
            source_id = str(asset.source_id)

        if asset.id not in asset_map:
            asset_map[asset.id] = {
                "id": str(asset.id),
                "name": asset.name,
                "preview_file_id": str(asset.preview_file_id or ""),
                "description": asset.description,
                "asset_type_name": entity_type_name,
                "asset_type_id": str(asset.entity_type_id),
                "canceled": asset.canceled,
                "episode_id": source_id,
                "data": fields.serialize_value(asset.data),
                "tasks": [],
            }

        if task_id is not None:
            if task_id not in task_map:
                task_dict = {
                    "id": str(task_id),
                    "entity_id": str(asset.id),
                    "task_status_id": str(task_status_id),
                    "task_type_id": str(task_type_id),
                    "priority": task_priority or 0,
                    "estimation": task_estimation,
                    "duration": task_duration,
                    "retake_count": task_retake_count,
                    "real_start_date": fields.serialize_value(
                        task_real_start_date
                    ),
                    "end_date": fields.serialize_value(task_end_date),
                    "start_date": fields.serialize_value(task_start_date),
                    "due_date": fields.serialize_value(task_due_date),
                    "last_comment_date": fields.serialize_value(
                        task_last_comment_date
                    ),
                    "assignees": [],
                }
                task_map[task_id] = task_dict
                asset_dict = asset_map[asset.id]
                asset_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(asset_map.values())
コード例 #10
0
 def serialize(self):
     attrs = inspect(self).attrs.keys()
     return {attr: serialize_value(getattr(self, attr)) for attr in attrs}
コード例 #11
0
ファイル: tasks_service.py プロジェクト: NeroSouza/zou
def get_person_tasks(person_id, projects, is_done=None):
    person = Person.get(person_id)
    project_ids = [project["id"] for project in projects]

    Sequence = aliased(Entity, name='sequence')
    Episode = aliased(Entity, name='episode')
    query = Task.query \
        .join(Project, TaskType, TaskStatus) \
        .join(Entity, Entity.id == Task.entity_id) \
        .join(EntityType, EntityType.id == Entity.entity_type_id) \
        .outerjoin(Sequence, Sequence.id == Entity.parent_id) \
        .outerjoin(Episode, Episode.id == Sequence.parent_id) \
        .filter(Task.assignees.contains(person)) \
        .filter(Project.id.in_(project_ids)) \
        .add_columns(
            Project.name,
            Entity.name,
            Entity.preview_file_id,
            EntityType.name,
            Sequence.name,
            Episode.name,
            TaskType.name,
            TaskStatus.name,
            TaskType.color,
            TaskStatus.color,
            TaskStatus.short_name
        )

    if is_done:
        query = query \
            .filter(TaskStatus.is_done == True) \
            .order_by(Task.end_date.desc(), TaskType.name, Entity.name)
    else:
        query = query.filter(TaskStatus.is_done == False)

    tasks = []
    for (task, project_name, entity_name, entity_preview_file_id,
         entity_type_name, sequence_name, episode_name, task_type_name,
         task_status_name, task_type_color, task_status_color,
         task_status_short_name) in query.all():
        if entity_preview_file_id is None:
            entity_preview_file_id = ""

        task_dict = task.serialize()
        task_dict.update({
            "project_name": project_name,
            "entity_name": entity_name,
            "entity_preview_file_id": str(entity_preview_file_id),
            "entity_type_name": entity_type_name,
            "sequence_name": sequence_name,
            "episode_name": episode_name,
            "task_type_name": task_type_name,
            "task_status_name": task_status_name,
            "task_type_color": task_type_color,
            "task_status_color": task_status_color,
            "task_status_short_name": task_status_short_name
        })
        tasks.append(task_dict)

    task_ids = [task["id"] for task in tasks]

    task_comment_map = {}
    comments = Comment.query \
        .filter(Comment.object_id.in_(task_ids)) \
        .order_by(Comment.object_id, Comment.created_at) \
        .all()

    task_id = None
    for comment in comments:
        if comment.object_id != task_id:
            task_id = fields.serialize_value(comment.object_id)
            task_comment_map[task_id] = {
                "text": comment.text,
                "date": fields.serialize_value(comment.created_at),
                "person_id": fields.serialize_value(comment.person_id)
            }
    for task in tasks:
        if task["id"] in task_comment_map:
            task["last_comment"] = task_comment_map[task["id"]]
        else:
            task["last_comment"] = {}

    return tasks
コード例 #12
0
ファイル: shots_service.py プロジェクト: ricekab/zou
def get_shots_and_tasks(criterions={}):
    """
    Get all shots for given criterions with related tasks for each shot.
    """
    shot_type = get_shot_type()
    shot_map = {}
    task_map = {}

    Sequence = aliased(Entity, name="sequence")
    Episode = aliased(Entity, name="episode")

    query = (Entity.query.join(Project).join(
        Sequence, Sequence.id == Entity.parent_id).outerjoin(
            Episode, Episode.id == Sequence.parent_id).outerjoin(
                Task, Task.entity_id == Entity.id).outerjoin(
                    assignees_table).add_columns(
                        Episode.name,
                        Episode.id,
                        Sequence.name,
                        Sequence.id,
                        Task.id,
                        Task.task_type_id,
                        Task.task_status_id,
                        Task.priority,
                        Task.estimation,
                        Task.duration,
                        Task.retake_count,
                        Task.real_start_date,
                        Task.end_date,
                        Task.start_date,
                        Task.due_date,
                        Task.last_comment_date,
                        assignees_table.columns.person,
                        Project.id,
                        Project.name,
                    ).filter(Entity.entity_type_id == shot_type["id"]))
    if "id" in criterions:
        query = query.filter(Entity.id == criterions["id"])

    if "project_id" in criterions:
        query = query.filter(Entity.project_id == criterions["project_id"])

    if "episode_id" in criterions:
        query = query.filter(Sequence.parent_id == criterions["episode_id"])

    for (
            shot,
            episode_name,
            episode_id,
            sequence_name,
            sequence_id,
            task_id,
            task_type_id,
            task_status_id,
            task_priority,
            task_estimation,
            task_duration,
            task_retake_count,
            task_real_start_date,
            task_end_date,
            task_start_date,
            task_due_date,
            task_last_comment_date,
            person_id,
            project_id,
            project_name,
    ) in query.all():
        shot_id = str(shot.id)

        shot.data = shot.data or {}

        if shot_id not in shot_map:

            shot_map[shot_id] = {
                "canceled": shot.canceled,
                "data": fields.serialize_value(shot.data),
                "description": shot.description,
                "entity_type_id": str(shot.entity_type_id),
                "episode_id": str(episode_id),
                "episode_name": episode_name or "",
                "fps": shot.data.get("fps", None),
                "frame_in": shot.data.get("frame_in", None),
                "frame_out": shot.data.get("frame_out", None),
                "id": str(shot.id),
                "name": shot.name,
                "nb_frames": shot.nb_frames,
                "parent_id": str(shot.parent_id),
                "preview_file_id": str(shot.preview_file_id or ""),
                "project_id": str(project_id),
                "project_name": project_name,
                "sequence_id": str(sequence_id),
                "sequence_name": sequence_name,
                "source_id": str(shot.source_id),
                "tasks": [],
                "type": "Shot",
            }

        if task_id is not None:
            if task_id not in task_map:
                task_dict = {
                    "id":
                    str(task_id),
                    "entity_id":
                    shot_id,
                    "task_status_id":
                    str(task_status_id),
                    "task_type_id":
                    str(task_type_id),
                    "priority":
                    task_priority or 0,
                    "estimation":
                    task_estimation,
                    "duration":
                    task_duration,
                    "retake_count":
                    task_retake_count,
                    "real_start_date":
                    fields.serialize_value(task_real_start_date),
                    "end_date":
                    fields.serialize_value(task_end_date),
                    "start_date":
                    fields.serialize_value(task_start_date),
                    "due_date":
                    fields.serialize_value(task_due_date),
                    "last_comment_date":
                    fields.serialize_value(task_last_comment_date),
                    "assignees": [],
                }
                task_map[task_id] = task_dict
                shot_dict = shot_map[shot_id]
                shot_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(shot_map.values())
コード例 #13
0
ファイル: playlists_service.py プロジェクト: tokejepsen/zou
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))
コード例 #14
0
ファイル: assets_service.py プロジェクト: cgwire/zou
def get_assets_and_tasks(criterions={}, page=1, with_episode_ids=False):
    """
    Get all assets for given criterions with related tasks for each asset.
    """
    asset_map = {}
    task_map = {}

    Episode = aliased(Entity, name="episode")

    query = (
        Entity.query.filter(build_asset_type_filter())
        .join(EntityType, Entity.entity_type_id == EntityType.id)
        .outerjoin(Task)
        .outerjoin(assignees_table)
    )

    tasks_query = query.add_columns(
        EntityType.name,
        Task.id,
        Task.task_type_id,
        Task.task_status_id,
        Task.priority,
        Task.estimation,
        Task.duration,
        Task.retake_count,
        Task.real_start_date,
        Task.end_date,
        Task.start_date,
        Task.due_date,
        Task.last_comment_date,
        assignees_table.columns.person,
    ).order_by(EntityType.name, Entity.name)

    if "id" in criterions:
        tasks_query = tasks_query.filter(Entity.id == criterions["id"])

    if "project_id" in criterions:
        tasks_query = tasks_query.filter(
            Entity.project_id == criterions["project_id"]
        )

    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":

            tasks_query = tasks_query.outerjoin(
                EntityLink, EntityLink.entity_out_id == Entity.id
            )
            tasks_query = tasks_query.filter(
                or_(
                    Entity.source_id == episode_id,
                    EntityLink.entity_in_id == episode_id,
                )
            )

    if "assigned_to" in criterions:
        tasks_query = tasks_query.filter(user_service.build_assignee_filter())
        del criterions["assigned_to"]

    cast_in_episode_ids = {}
    if "project_id" in criterions or with_episode_ids:
        episode_links_query = (
            EntityLink.query.join(
                Episode, EntityLink.entity_in_id == Episode.id
            )
            .join(EntityType, EntityType.id == Episode.entity_type_id)
            .filter(EntityType.name == "Episode")
            .order_by(Episode.name)
        )

        if "project_id" in criterions:
            episode_links_query = episode_links_query.filter(
                Episode.project_id == criterions["project_id"]
            )
        for link in episode_links_query.all():
            if str(link.entity_out_id) not in cast_in_episode_ids:
                cast_in_episode_ids[str(link.entity_out_id)] = []
            cast_in_episode_ids[str(link.entity_out_id)].append(
                str(link.entity_in_id)
            )

    for (
        asset,
        entity_type_name,
        task_id,
        task_type_id,
        task_status_id,
        task_priority,
        task_estimation,
        task_duration,
        task_retake_count,
        task_real_start_date,
        task_end_date,
        task_start_date,
        task_due_date,
        task_last_comment_date,
        person_id,
    ) in tasks_query.all():

        if asset.source_id is None:
            source_id = ""
        else:
            source_id = str(asset.source_id)

        asset_id = str(asset.id)

        if asset_id not in asset_map:
            asset_map[asset_id] = {
                "id": asset_id,
                "name": asset.name,
                "preview_file_id": str(asset.preview_file_id or ""),
                "description": asset.description,
                "asset_type_name": entity_type_name,
                "asset_type_id": str(asset.entity_type_id),
                "canceled": asset.canceled,
                "ready_for": str(asset.ready_for),
                "episode_id": source_id,
                "casting_episode_ids": cast_in_episode_ids.get(asset_id, []),
                "is_casting_standby": asset.is_casting_standby,
                "data": fields.serialize_value(asset.data),
                "tasks": [],
            }

        if task_id is not None:
            if task_id not in task_map:
                task_dict = {
                    "id": str(task_id),
                    "entity_id": asset_id,
                    "task_status_id": str(task_status_id),
                    "task_type_id": str(task_type_id),
                    "priority": task_priority or 0,
                    "estimation": task_estimation,
                    "duration": task_duration,
                    "retake_count": task_retake_count,
                    "real_start_date": fields.serialize_value(
                        task_real_start_date
                    ),
                    "end_date": fields.serialize_value(task_end_date),
                    "start_date": fields.serialize_value(task_start_date),
                    "due_date": fields.serialize_value(task_due_date),
                    "last_comment_date": fields.serialize_value(
                        task_last_comment_date
                    ),
                    "assignees": [],
                }
                task_map[task_id] = task_dict
                asset_dict = asset_map[asset_id]
                asset_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(asset_map.values())
コード例 #15
0
ファイル: entities_service.py プロジェクト: ricekab/zou
def get_entities_and_tasks(criterions={}):
    """
    Get all entities for given criterions with related tasks for each entity.
    """
    entity_map = {}
    task_map = {}

    query = (Entity.query.outerjoin(
        Task,
        Task.entity_id == Entity.id).outerjoin(assignees_table).add_columns(
            Task.id,
            Task.task_type_id,
            Task.task_status_id,
            Task.priority,
            assignees_table.columns.person,
        ))

    if "entity_type_id" in criterions:
        query = query.filter(
            Entity.entity_type_id == criterions["entity_type_id"])

    if "project_id" in criterions:
        query = query.filter(Entity.project_id == criterions["project_id"])

    for (
            entity,
            task_id,
            task_type_id,
            task_status_id,
            task_priority,
            person_id,
    ) in query.all():
        entity_id = str(entity.id)

        entity.data = entity.data or {}

        if entity_id not in entity_map:
            entity_map[entity_id] = {
                "id": str(entity.id),
                "name": entity.name,
                "description": entity.description,
                "frame_in": entity.data.get("frame_in", None),
                "frame_out": entity.data.get("frame_out", None),
                "fps": entity.data.get("fps", None),
                "preview_file_id": str(entity.preview_file_id or ""),
                "canceled": entity.canceled,
                "data": fields.serialize_value(entity.data),
                "tasks": [],
            }

        if task_id is not None:

            if task_id not in task_map:
                task_dict = {
                    "id": str(task_id),
                    "entity_id": entity_id,
                    "task_status_id": str(task_status_id),
                    "task_type_id": str(task_type_id),
                    "priority": task_priority or 0,
                    "assignees": [],
                }
                task_map[task_id] = task_dict
                entity_dict = entity_map[entity_id]
                entity_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(entity_map.values())
コード例 #16
0
def all_assets_and_tasks(criterions={}, page=1):
    shot_type = shots_service.get_shot_type()
    sequence_type = shots_service.get_sequence_type()
    episode_type = shots_service.get_episode_type()
    scene_type = shots_service.get_scene_type()
    asset_map = {}
    task_map = {}

    query = Entity.query \
        .join(EntityType) \
        .outerjoin(Task) \
        .outerjoin(assignees_table) \
        .add_columns(
            EntityType.name,
            Task.id,
            Task.task_type_id,
            Task.task_status_id,
            assignees_table.columns.person
        ) \
        .order_by(
            EntityType.name,
            Entity.name
        ) \
        .filter(
            ~Entity.entity_type_id.in_([
                shot_type["id"],
                scene_type["id"],
                sequence_type["id"],
                episode_type["id"]
            ])
        )

    if "project_id" in criterions:
        query = query.filter(Entity.project_id == criterions["project_id"])

    for (asset, entity_type_name, task_id, task_type_id, task_status_id,
         person_id) in query.all():

        if asset.id not in asset_map:
            asset_map[asset.id] = {
                "id": str(asset.id),
                "name": asset.name,
                "preview_file_id": str(asset.preview_file_id or ""),
                "description": asset.description,
                "asset_type_name": entity_type_name,
                "asset_type_id": str(asset.entity_type_id),
                "canceled": asset.canceled,
                "data": fields.serialize_value(asset.data),
                "tasks": []
            }

        if task_id is not None:
            if task_id not in task_map:
                task_dict = {
                    "id": str(task_id),
                    "entity_id": str(asset.id),
                    "task_status_id": str(task_status_id),
                    "task_type_id": str(task_type_id),
                    "assignees": []
                }
                task_map[task_id] = task_dict
                asset_dict = asset_map[asset.id]
                asset_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(asset_map.values())
コード例 #17
0
def get_shots_and_tasks(criterions={}):
    """
    Get all shots for given criterions with related tasks for each shot.
    """
    shot_type = get_shot_type()
    shot_map = {}
    task_map = {}

    Sequence = aliased(Entity, name='sequence')
    Episode = aliased(Entity, name='episode')

    query = Entity.query \
        .join(Sequence, Sequence.id == Entity.parent_id) \
        .outerjoin(Episode, Episode.id == Sequence.parent_id) \
        .outerjoin(Task, Task.entity_id == Entity.id) \
        .outerjoin(assignees_table) \
        .add_columns(
            Episode.name,
            Episode.id,
            Sequence.name,
            Sequence.id,
            Task.id,
            Task.task_type_id,
            Task.task_status_id,
            assignees_table.columns.person
        ) \
        .filter(Entity.entity_type_id == shot_type["id"]) \

    if "project_id" in criterions:
        query = query.filter(Entity.project_id == criterions["project_id"]) \

    for (shot, episode_name, episode_id, sequence_name, sequence_id, task_id,
         task_type_id, task_status_id, person_id) in query.all():
        shot_id = str(shot.id)

        shot.data = shot.data or {}

        if shot_id not in shot_map:
            shot_map[shot_id] = {
                "id": str(shot.id),
                "name": shot.name,
                "description": shot.description,
                "frame_in": shot.data.get("frame_in", None),
                "frame_out": shot.data.get("frame_out", None),
                "fps": shot.data.get("fps", None),
                "preview_file_id": str(shot.preview_file_id or ""),
                "episode_id": str(episode_id),
                "episode_name": episode_name,
                "sequence_id": str(sequence_id),
                "sequence_name": sequence_name,
                "canceled": shot.canceled,
                "data": fields.serialize_value(shot.data),
                "tasks": []
            }

        if task_id is not None:

            if task_id not in task_map:
                task_dict = {
                    "id": str(task_id),
                    "entity_id": shot_id,
                    "task_status_id": str(task_status_id),
                    "task_type_id": str(task_type_id),
                    "assignees": []
                }
                task_map[task_id] = task_dict
                shot_dict = shot_map[shot_id]
                shot_dict["tasks"].append(task_dict)

            if person_id:
                task_map[task_id]["assignees"].append(str(person_id))

    return list(shot_map.values())
コード例 #18
0
def get_cast_in(asset_id):
    """
    Get the list of shots where an asset is casted in.
    """
    cast_in = []
    Sequence = aliased(Entity, name="sequence")
    Episode = aliased(Entity, name="episode")
    links = (
        EntityLink.query.filter_by(entity_out_id=asset_id)
        .filter(Entity.canceled != True)
        .join(Entity, EntityLink.entity_in_id == Entity.id)
        .join(Sequence, Entity.parent_id == Sequence.id)
        .outerjoin(Episode, Sequence.parent_id == Episode.id)
        .add_columns(
            Entity.name,
            Sequence.name,
            Episode.id,
            Episode.name,
            Entity.preview_file_id,
        )
        .order_by(Episode.name, Sequence.name, Entity.name)
    )

    for (
        link,
        entity_name,
        sequence_name,
        episode_id,
        episode_name,
        entity_preview_file_id,
    ) in links:
        shot = {
            "shot_id": fields.serialize_value(link.entity_in_id),
            "shot_name": entity_name,
            "sequence_name": sequence_name,
            "episode_id": str(episode_id),
            "episode_name": episode_name,
            "preview_file_id": fields.serialize_value(entity_preview_file_id),
            "nb_occurences": link.nb_occurences,
        }
        cast_in.append(shot)

    links = (
        EntityLink.query.filter_by(entity_out_id=asset_id)
        .filter(Entity.canceled != True)
        .filter(assets_service.build_entity_type_asset_type_filter())
        .join(Entity, EntityLink.entity_in_id == Entity.id)
        .join(EntityType, EntityType.id == Entity.entity_type_id)
        .add_columns(Entity.name, EntityType.name, Entity.preview_file_id)
        .order_by(EntityType.name, Entity.name)
    )

    for (link, entity_name, entity_type_name, entity_preview_file_id) in links:
        shot = {
            "asset_id": fields.serialize_value(link.entity_in_id),
            "asset_name": entity_name,
            "asset_type_name": entity_type_name,
            "preview_file_id": fields.serialize_value(entity_preview_file_id),
            "nb_occurences": link.nb_occurences,
        }
        cast_in.append(shot)

    return cast_in