Exemplo n.º 1
0
def update_casting(entity_id, casting):
    """
    Update casting for given entity. Casting is an array of dictionaries made of
    two fields: `asset_id` and `nb_occurences`.
    """

    entity = entities_service.get_entity_raw(entity_id)
    entity_dict = entity.serialize(relations=True)
    if shots_service.is_episode(entity_dict):
        assets = _extract_removal(entity_dict, casting)
        for asset_id in assets:
            _remove_asset_from_episode_shots(asset_id, entity_id)
    entity.update({"entities_out": [], "entities_out_length": 0})
    for cast in casting:
        if "asset_id" in cast and "nb_occurences" in cast:
            create_casting_link(
                entity.id,
                cast["asset_id"],
                nb_occurences=cast["nb_occurences"],
                label=cast.get("label", ""),
            )
            if shots_service.is_episode(entity_dict):
                events.emit(
                    "asset:update",
                    {"asset_id": cast["asset_id"]},
                    project_id=entity.project_id,
                )

    entity_id = str(entity.id)
    nb_entities_out = len(casting)
    entity.update({"nb_entities_out": nb_entities_out})
    entity_dict = entity.serialize()
    if shots_service.is_shot(entity_dict):
        refresh_shot_casting_stats(entity_dict)
        events.emit(
            "shot:casting-update",
            {
                "shot_id": entity_id,
                "nb_entities_out": nb_entities_out
            },
            project_id=str(entity.project_id),
        )
    elif shots_service.is_episode(entity_dict):
        events.emit(
            "episode:casting-update",
            {
                "episode_id": entity_id,
                "nb_entities_out": nb_entities_out
            },
            project_id=str(entity.project_id),
        )
    else:
        events.emit(
            "asset:casting-update",
            {"asset_id": entity_id},
            project_id=str(entity.project_id),
        )
    return casting
Exemplo n.º 2
0
    def put(self, instance_id):
        """
        Update a model with data given in the request body. JSON format is
        expected. Model performs the validation automatically when fields are
        modified.
        """
        try:
            data = self.get_arguments()
            entity = self.get_model_or_404(instance_id)
            self.check_update_permissions(entity.serialize(), data)

            extra_data = copy.copy(entity.data) or {}
            if "data" not in data or data["data"] is None:
                data["data"] = {}
            extra_data.update(data["data"])
            data["data"] = extra_data

            previous_version = entity.serialize()
            data = self.update_data(data, instance_id)
            if data.get("source_id", None) == "null":
                data["source_id"] = None

            is_ready_for_changed = \
                str(entity.ready_for) != data.get("ready_for", "")
            entity.update(data)
            entity_dict = self.serialize_instance(entity)

            if shots_service.is_shot(entity_dict):
                shots_service.clear_shot_cache(entity_dict["id"])
                self.save_version_if_needed(entity_dict, previous_version)
            elif assets_service.is_asset(entity):
                if is_ready_for_changed:
                    breakdown_service.refresh_casting_stats(entity_dict)
                assets_service.clear_asset_cache(entity_dict["id"])
            elif shots_service.is_sequence(entity_dict):
                shots_service.clear_sequence_cache(entity_dict["id"])
            elif shots_service.is_episode(entity_dict):
                shots_service.clear_episode_cache(entity_dict["id"])

            self.emit_update_event(entity_dict)
            return entity_dict, 200

        except StatementError as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"error": True, "message": str(exception)}, 400
        except TypeError as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"error": True, "message": str(exception)}, 400
        except IntegrityError as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"error": True, "message": str(exception)}, 400
        except StatementError as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"error": True, "message": str(exception)}, 400
        except NotFound as exception:
            return {"error": True, "message": str(exception)}, 404
        except Exception as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"error": True, "message": str(exception)}, 400
Exemplo n.º 3
0
 def get_type_name(self, entity_dict):
     type_name = "asset"
     if shots_service.is_shot(entity_dict):
         type_name = "shot"
     elif shots_service.is_sequence(entity_dict):
         type_name = "sequence"
     elif shots_service.is_episode(entity_dict):
         type_name = "episode"
     return type_name
Exemplo n.º 4
0
def get_file_name_template(tree, mode, entity):
    try:
        if entity["type"] == "AssetInstance":
            if entity.get("target_asset_id", None) is not None:
                return tree[mode]["file_name"]["instance_asset"]
            else:
                return tree[mode]["file_name"]["instance"]
        elif shots_service.is_shot(entity):
            return tree[mode]["file_name"]["shot"]
        elif shots_service.is_sequence(entity):
            return tree[mode]["file_name"]["sequence"]
        elif shots_service.is_scene(entity):
            return tree[mode]["file_name"]["scene"]
        elif shots_service.is_episode(entity):
            return tree[mode]["file_name"]["episode"]
        else:
            return tree[mode]["file_name"]["asset"]
    except KeyError:
        raise MalformedFileTreeException