Ejemplo n.º 1
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
Ejemplo n.º 2
0
 def put(self, preview_file_id):
     preview_file = files_service.get_preview_file(preview_file_id)
     task = tasks_service.get_task(preview_file["task_id"])
     user_service.check_project_access(task["project_id"])
     user_service.check_entity_access(task["entity_id"])
     asset = entities_service.update_entity_preview(task["entity_id"],
                                                    preview_file_id)
     assets_service.clear_asset_cache(asset["id"])
     shots_service.clear_shot_cache(asset["id"])
     return asset
Ejemplo n.º 3
0
 def emit_event(self, event_name, entity_dict):
     instance_id = entity_dict["id"]
     type_name = shots_service.get_base_entity_type_name(entity_dict)
     if event_name in ["update", "delete"]:
         if type_name == "shot":
             shots_service.clear_shot_cache(instance_id)
         if type_name == "asset":
             assets_service.clear_asset_cache(instance_id)
     events.emit("%s:%s" % (type_name.lower(), event_name),
                 {"%s_id" % type_name.lower(): instance_id},
                 project_id=entity_dict["project_id"])
Ejemplo n.º 4
0
    def post_processing(self):
        # We handle the fact that an asset can have multiple parents by using
        # the entities out field as a children field.
        for key in self.parent_map.keys():
            try:
                asset = assets_service.get_asset_by_shotgun_id(key)
                data = {"entities_out": self.parent_map[key]}
                assets_service.update_asset(asset["id"], data)
                assets_service.clear_asset_cache(asset["id"])
            except AssetNotFoundException:
                pass

        return self.parent_map
Ejemplo n.º 5
0
 def emit_event(self, event_name, entity_dict, data={}):
     instance_id = entity_dict["id"]
     type_name = shots_service.get_base_entity_type_name(entity_dict)
     if event_name in ["update", "delete"]:
         if type_name == "shot":
             shots_service.clear_shot_cache(instance_id)
         if type_name == "asset":
             assets_service.clear_asset_cache(instance_id)
     content = {
         "%s_id" % type_name: instance_id,
         type_name: entity_dict,
     }
     content.update(data)
     events.emit("%s:%s" % (type_name, event_name),
                 content,
                 project_id=entity_dict["project_id"])
Ejemplo n.º 6
0
 def save_entity(self, data):
     entity = None
     try:
         entity = assets_service.get_raw_asset_by_shotgun_id(
             data["shotgun_id"])
         entity.update(data)
         assets_service.clear_asset_cache(str(entity.id))
         current_app.logger.info("Entity updated: %s" % entity)
     except AssetNotFoundException:
         if data.get("entity_type_id", None) is not None:
             entity = Entity(**data)
             entity.save()
             current_app.logger.info("Entity created: %s" % entity)
         else:
             current_app.logger.info("Entity ignored: %s" % data["name"])
     return entity
Ejemplo n.º 7
0
    def post_processing(self):
        # We handle the fact that an asset can have multiple parents by using
        # the entities out field as a children field.
        for key in self.parent_map.keys():
            try:
                asset = assets_service.get_asset_by_shotgun_id(key)

                asset = assets_service.get_full_asset(asset['id'])
                former_children = [
                    Entity.get(child_id)
                    for child_id in asset.get('entities_out', [])
                ]
                children = list(set(self.parent_map[key] + former_children))
                data = {"entities_out": children}

                assets_service.update_asset(asset["id"], data)
                assets_service.clear_asset_cache(asset["id"])
            except AssetNotFoundException:
                pass

        return self.parent_map