Beispiel #1
0
def get_projects_with_extra_data(query, for_client=False):
    """
    Helpers function to attach:
    * First episode name to current project when it's a TV Show.
    * Add metadata descriptors for this project.
    """
    projects = []
    for project in query.all():
        project_dict = project.serialize(relations=True)
        if for_client:
            descriptors = MetadataDescriptor.get_all_by(project_id=project.id,
                                                        for_client=True)
        else:
            descriptors = MetadataDescriptor.get_all_by(project_id=project.id)
        project_dict["descriptors"] = []
        for descriptor in descriptors:
            project_dict["descriptors"].append({
                "id":
                fields.serialize_value(descriptor.id),
                "name":
                descriptor.name,
                "field_name":
                descriptor.field_name,
                "choices":
                descriptor.choices,
                "for_client":
                descriptor.for_client or False,
                "entity_type":
                descriptor.entity_type,
                "departments":
                [str(department.id) for department in descriptor.departments],
            })

        project_dict["task_types_priority"] = {
            str(task_type_link.task_type_id): task_type_link.priority
            for task_type_link in ProjectTaskTypeLink.query.filter_by(
                project_id=project.id)
        }

        if project.production_type == "tvshow":
            first_episode = (Entity.query.join(EntityType).filter(
                EntityType.name == "Episode").filter(
                    Entity.project_id == project.id).order_by(
                        Entity.name).first())
            if first_episode is not None:
                project_dict["first_episode_id"] = fields.serialize_value(
                    first_episode.id)

        projects.append(project_dict)
    return projects
Beispiel #2
0
def get_projects_with_extra_data(query):
    """
    Helpers function to attach:
    * First episode name to current project when it's a TV Show.
    * Add metadata descriptors for this project.
    """
    projects = []
    for project in query.all():
        project_dict = project.serialize()

        descriptors = MetadataDescriptor.get_all_by(project_id=project.id)
        project_dict["descriptors"] = []
        for descriptor in descriptors:
            project_dict["descriptors"].append({
                "id":
                fields.serialize_value(descriptor.id),
                "name":
                descriptor.name,
                "field_name":
                descriptor.field_name,
                "choices":
                descriptor.choices,
                "entity_type":
                descriptor.entity_type
            })

        if project.production_type == "tvshow":
            first_episode = Entity.query \
                .join(EntityType) \
                .filter(EntityType.name == 'Episode') \
                .filter(Entity.project_id == project.id) \
                .order_by(Entity.name) \
                .first()
            if first_episode is not None:
                project_dict["first_episode_id"] = \
                    fields.serialize_value(first_episode.id)

        projects.append(project_dict)
    return projects