コード例 #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
コード例 #2
0
def add_metadata_descriptor(project_id,
                            entity_type,
                            name,
                            choices,
                            for_client,
                            departments=[]):
    if not departments:
        departments = []

    try:
        departments_objects = [
            Department.get(department_id) for department_id in departments
            if department_id is not None
        ]
    except StatementError:
        raise DepartmentNotFoundException()

    descriptor = MetadataDescriptor.create(
        project_id=project_id,
        entity_type=entity_type,
        name=name,
        choices=choices,
        for_client=for_client,
        departments=departments_objects,
        field_name=slugify.slugify(name, separator="_"),
    )
    events.emit(
        "metadata-descriptor:new",
        {"metadata_descriptor_id": str(descriptor.id)},
        project_id=project_id,
    )
    clear_project_cache(project_id)
    return descriptor.serialize()
コード例 #3
0
 def generate_fixture_metadata_descriptor(self, entity_type="Asset"):
     self.meta_descriptor = MetadataDescriptor.create(
         project_id=self.project.id,
         name="Contractor",
         field_name="contractor",
         choices=["value 1", "value 2"],
         entity_type=entity_type)
     return self.meta_descriptor
コード例 #4
0
def add_metadata_descriptor(project_id, entity_type, name, choices):
    descriptor = MetadataDescriptor.create(project_id=project_id,
                                           entity_type=entity_type,
                                           name=name,
                                           choices=choices,
                                           field_name=slugify.slugify(
                                               name, separator="_"))

    events.emit("metadata-descriptor:new",
                {"descriptor_id": str(descriptor.id)})
    return descriptor.serialize()
コード例 #5
0
    def test_export_with_metadata(self):
        MetadataDescriptor.create(
            project_id=self.project.id,
            name="Start frame",
            field_name="start_frame",
            choices=["0", "100"],
            entity_type="Edit",
        )
        self.edit.update(
            {
                "data": {
                    "start_frame": "100",
                }
            }
        )
        csv_edits = self.get_raw(
            "/export/csv/projects/%s/edits.csv" % self.project.id
        )
        expected_result = """Project;Episode;Name;Description;Time Spent;Start frame;Edit\r
Cosmos Landromat;E01;Edit;Description of the Edit;0.21;100;opn\r\n"""
        self.assertEqual(csv_edits, expected_result)
コード例 #6
0
 def test_add_asset_metadata_descriptor(self):
     descriptor = projects_service.add_metadata_descriptor(
         self.project.id, "Asset", "Is Outdoor", [])
     self.assertIsNotNone(MetadataDescriptor.get(descriptor["id"]))
     descriptor = projects_service.add_metadata_descriptor(
         self.project.id, "Asset", "Contractor",
         ["contractor 1", "contractor 2"])
     descriptors = projects_service.get_metadata_descriptors(
         self.project.id)
     self.assertEqual(len(descriptors), 2)
     self.assertEqual(descriptors[0]["id"], descriptor["id"])
     self.assertEqual(descriptors[0]["field_name"], "contractor")
     self.assertEqual(descriptors[1]["field_name"], "is_outdoor")
コード例 #7
0
ファイル: deletion_service.py プロジェクト: cgwire/zou
def remove_project(project_id):
    from zou.app.services import playlists_service

    tasks = Task.query.filter_by(project_id=project_id)
    for task in tasks:
        remove_task(task.id, force=True)

    query = EntityLink.query.join(Entity,
                                  EntityLink.entity_in_id == Entity.id).filter(
                                      Entity.project_id == project_id)
    for link in query:
        link.delete_no_commit()
    EntityLink.commit()

    query = EntityVersion.query.join(
        Entity, EntityVersion.entity_id == Entity.id).filter(
            Entity.project_id == project_id)
    for version in query:
        version.delete_no_commit()
    EntityLink.commit()

    playlists = Playlist.query.filter_by(project_id=project_id)
    for playlist in playlists:
        playlists_service.remove_playlist(playlist.id)

    ApiEvent.delete_all_by(project_id=project_id)
    Entity.delete_all_by(project_id=project_id)
    MetadataDescriptor.delete_all_by(project_id=project_id)
    Milestone.delete_all_by(project_id=project_id)
    ScheduleItem.delete_all_by(project_id=project_id)
    SearchFilter.delete_all_by(project_id=project_id)

    for news in News.query.join(Task).filter_by(project_id=project_id).all():
        news.delete_no_commit()
    News.commit()
    project = Project.get(project_id)
    project.delete()
    events.emit("project:delete", {"project_id": project.id})
    return project_id
コード例 #8
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