Ejemplo n.º 1
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
Ejemplo n.º 2
0
def remove_asset_instance_for_shot(shot_id, asset_instance_id):
    """
    Remove asset instance from instance casting of given shot.
    """
    shot = shots_service.get_shot_raw(shot_id)
    asset_instance = assets_service.get_asset_instance_raw(asset_instance_id)
    shot.instance_casting.remove(asset_instance)
    shot.save()
    return shot.serialize()
Ejemplo n.º 3
0
def add_asset_instance_to_shot(shot_id, asset_instance_id):
    """
    Add asset instance to instance casting of given shot.
    """
    shot = shots_service.get_shot_raw(shot_id)
    asset_instance = assets_service.get_asset_instance_raw(asset_instance_id)
    shot.instance_casting.append(asset_instance)
    shot.save()
    return shot.serialize()
Ejemplo 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
Ejemplo n.º 5
0
def get_asset_instances_for_shot(shot_id):
    """
    Return asset instances casted in given shot.
    """
    shot = shots_service.get_shot_raw(shot_id)

    result = {}
    for asset_instance in shot.instance_casting:
        asset_id = str(asset_instance.asset_id)
        if asset_id not in result:
            result[asset_id] = []
        result[asset_id].append(asset_instance.serialize())
    return result
Ejemplo n.º 6
0
def remove_asset_instance_for_shot(shot_id, asset_instance_id):
    """
    Remove asset instance from instance casting of given shot.
    """
    shot = shots_service.get_shot_raw(shot_id)
    asset_instance = assets_service.get_asset_instance_raw(asset_instance_id)
    shot.instance_casting.remove(asset_instance)
    shot.save()
    events.emit("asset_instance:remove-from-shot", {
        "shot_id": shot_id,
        "asset_instance_id": asset_instance_id
    })
    return shot.serialize()
Ejemplo n.º 7
0
def add_asset_instance_to_shot(shot_id, asset_instance_id):
    """
    Add asset instance to instance casting of given shot.
    """
    shot = shots_service.get_shot_raw(shot_id)
    asset_instance = assets_service.get_asset_instance_raw(asset_instance_id)
    shot.instance_casting.append(asset_instance)
    shot.save()

    events.emit("asset_instance:add-to-shot", {
        "shot_id": shot_id,
        "asset_instance_id": asset_instance_id
    })
    return shot.serialize()
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def _remove_asset_from_episode_shots(asset_id, episode_id):
    shots = shots_service.get_shots_for_episode(episode_id)
    shot_ids = [shot["id"] for shot in shots]
    links = EntityLink.query.filter(
        EntityLink.entity_in_id.in_(shot_ids)).filter(
            EntityLink.entity_out_id == asset_id)
    for link in links:
        shot = shots_service.get_shot_raw(str(link.entity_in_id))
        shot.update({"nb_entities_out": shot.nb_entities_out - 1})
        refresh_shot_casting_stats(shot.serialize())
        link.delete()
        events.emit(
            "shot:casting-update",
            {
                "shot_id": str(shot.id),
                "nb_entities_out": shot.nb_entities_out
            },
            project_id=str(shot.project_id),
        )
    return shots