Exemplo 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
Exemplo 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
Exemplo n.º 3
0
 def get(self, shot_id):
     """
     Retrieve given shot.
     """
     shot = shots_service.get_full_shot(shot_id)
     if shot is None:
         shots_service.clear_shot_cache(shot_id)
         shot = shots_service.get_full_shot(shot_id)
     user_service.check_project_access(shot["project_id"])
     return shot
Exemplo n.º 4
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"])
Exemplo 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"])
Exemplo n.º 6
0
    def import_entry(self, data):
        shot = Entity.get_by(
            shotgun_id=data["shotgun_id"],
            entity_type_id=shots_service.get_shot_type()["id"],
        )

        if shot is None:
            shot = Entity(**data)
            shot.save()
            current_app.logger.info("Shot created: %s" % shot)

        else:
            if shot.data is None:
                shot.data = {}
            shot.update(data)
            shot.data.update(data["data"])
            shot.save()
            shots_service.clear_shot_cache(str(shot.id))
            current_app.logger.info("Shot updated: %s" % shot)

        return shot