Exemplo n.º 1
0
def create_casting_link(entity_in_id, asset_id, nb_occurences=1, label=""):
    """
    Add a link between given entity and given asset.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id, entity_out_id=asset_id)
    entity = entities_service.get_entity(entity_in_id)
    project_id = str(entity["project_id"])
    if link is None:
        link = EntityLink.create(
            entity_in_id=entity_in_id,
            entity_out_id=asset_id,
            nb_occurences=nb_occurences,
            label=label,
        )
        events.emit("entity-link:new", {
            "entity_link_id": link.id,
            "entity_in_id": link.entity_in_id,
            "entity_out_id": link.entity_out_id,
            "nb_occurences": nb_occurences
        },
                    project_id=project_id)
    else:
        link.update({"nb_occurences": nb_occurences, "label": label})
        events.emit("entity-link:update", {
            "entity_link_id": link.id,
            "nb_occurences": nb_occurences
        },
                    project_id=project_id)
    return link
Exemplo n.º 2
0
def remove_shot(shot_id, force=False):
    """
    Remove given shot from database. If it has tasks linked to it, it marks
    the shot as canceled. Deletion can be forced.
    """
    shot = get_shot_raw(shot_id)
    is_tasks_related = Task.query.filter_by(entity_id=shot_id).count() > 0

    if is_tasks_related and not force:
        shot.update({"canceled": True})
        clear_shot_cache(shot_id)
        events.emit("shot:update", {"shot_id": shot_id},
                    project_id=str(shot.project_id))
    else:
        from zou.app.services import tasks_service

        tasks = Task.query.filter_by(entity_id=shot_id).all()
        for task in tasks:
            deletion_service.remove_task(task.id, force=True)
            tasks_service.clear_task_cache(str(task.id))

        EntityVersion.delete_all_by(entity_id=shot_id)
        Subscription.delete_all_by(entity_id=shot_id)
        EntityLink.delete_all_by(entity_in_id=shot_id)
        shot.delete()
        clear_shot_cache(shot_id)
        events.emit("shot:delete", {"shot_id": shot_id},
                    project_id=str(shot.project_id))

    deleted_shot = shot.serialize(obj_type="Shot")
    return deleted_shot
Exemplo n.º 3
0
def update_casting(shot_id, casting):
    shot = shots_service.get_shot_raw(shot_id)
    shot.update({"entities_out": []})
    for cast in casting:
        EntityLink.create(entity_in_id=shot.id,
                          entity_out_id=cast["asset_id"],
                          nb_occurences=cast["nb_occurences"])
    return casting
Exemplo n.º 4
0
def update_casting(shot_id, casting):
    """
    Update casting for given shot. Casting is an array of dictionaries made of
    two fields: `asset_id` and `nb_occurences`.
    """
    shot = shots_service.get_shot_raw(shot_id)
    shot.update({"entities_out": []})
    for cast in casting:
        EntityLink.create(entity_in_id=shot.id,
                          entity_out_id=cast["asset_id"],
                          nb_occurences=cast["nb_occurences"])
    return casting
Exemplo n.º 5
0
 def test_entity_link(self):
     entity_link_dict = {
         "id": "726f9b44-526f-4fce-a979-6bf8bc8962a4",
         "created_at": "2019-06-28T09:47:42",
         "updated_at": "2019-06-28T09:47:42",
         "entity_in_id": str(self.shot.id),
         "entity_out_id": str(self.asset.id),
         "nb_occurences": 1,
         "label": "animation",
         "type": "EntityLink"
     }
     EntityLink.create_from_import(entity_link_dict)
     entity_link = EntityLink.get_by(id=entity_link_dict["id"])
     self.assertEqual(entity_link_dict["label"], entity_link.label)
Exemplo n.º 6
0
def create_casting_link(entity_in_id, asset_id, nb_occurences=1, label=""):
    """
    Add a link between given entity and given asset.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id, entity_out_id=asset_id)
    if link is None:
        link = EntityLink.create(
            entity_in_id=entity_in_id,
            entity_out_id=asset_id,
            nb_occurences=nb_occurences,
            label=label,
        )
    else:
        link.update({"nb_occurences": nb_occurences, "label": label})
    return link
Exemplo n.º 7
0
def remove_entity_link(link_id):
    try:
        link = EntityLink.get_by(id=link_id)
        link.delete()
        return link.serialize()
    except:
        raise EntityLinkNotFoundException
Exemplo n.º 8
0
def get_entity_link_raw(entity_in_id, entity_out_id):
    """
    Get link matching given entities.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id,
                             entity_out_id=entity_out_id)
    return link
Exemplo n.º 9
0
def update_casting(shot_id, casting):
    """
    Update casting for given shot. Casting is an array of dictionaries made of
    two fields: `asset_id` and `nb_occurences`.
    """
    shot = shots_service.get_shot_raw(shot_id)
    shot.update({"entities_out": []})
    casting_ids = []
    for cast in casting:
        if "asset_id" in cast and "nb_occurences" in cast:
            EntityLink.create(entity_in_id=shot.id,
                              entity_out_id=cast["asset_id"],
                              nb_occurences=cast["nb_occurences"])
    events.emit("shot:casting-update", {
        "shot": shot_id,
        "casting": casting_ids
    })
    return casting
Exemplo n.º 10
0
def get_entity_link(entity_in_id, entity_out_id):
    """
    Get link matching given entities.
    """
    link = EntityLink.get_by(entity_in_id=entity_in_id,
                             entity_out_id=entity_out_id)
    if link:
        return link.serialize()
    else:
        return None
Exemplo n.º 11
0
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
Exemplo n.º 12
0
def _create_episode_casting_link(entity, asset_id, nb_occurences=1, label=""):
    """
    When an asset is casted in a shot, the asset is automatically casted in
    the episode.
    """
    if shots_service.is_shot(entity):
        sequence = shots_service.get_sequence(entity["parent_id"])
        if sequence["parent_id"] is not None:
            link = EntityLink.get_by(entity_in_id=sequence["parent_id"],
                                     entity_out_id=asset_id)
            if link is None:
                link = EntityLink.create(
                    entity_in_id=sequence["parent_id"],
                    entity_out_id=asset_id,
                    nb_occurences=1,
                    label=label,
                )
                events.emit(
                    "asset:update",
                    {"asset_id": asset_id},
                    project_id=entity["project_id"],
                )
    return entity
Exemplo n.º 13
0
    def test_import_casting_twice(self):
        path = "/import/csv/projects/%s/casting" % self.project_id
        self.upload_csv(path, "casting")
        path = "/import/csv/projects/%s/casting" % self.project_id
        self.upload_csv(path, "casting")
        links = EntityLink.query.all()
        self.assertEqual(len(links), 18)
        self.assertEqual(get_shot(self.e01seq01sh01_id)["nb_entities_out"], 2)

        path = "/import/csv/projects/%s/casting" % self.project_id
        self.upload_csv(path, "casting_02")
        links = EntityLink.query.all()
        self.assertEqual(len(links), 18)
        link = EntityLink.get_by(
            entity_in_id=self.e01seq01sh01_id,
            entity_out_id=self.asset_victor_id,
        )
        self.assertEqual(link.label, "fixed")
        self.assertEqual(get_shot(self.e01seq01sh01_id)["nb_entities_out"], 2)