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}) 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) shot.delete() clear_shot_cache(shot_id) events.emit("shot:delete", {"shot_id": shot_id}) deleted_shot = shot.serialize(obj_type="Shot") return deleted_shot
def save_version_if_needed(self, shot, previous_shot): previous_data = previous_shot.get("data", {}) or {} data = shot.get("data", {}) frame_in = data.get("frame_in", 0) pframe_in = previous_data.get("frame_in", 0) frame_out = data.get("frame_in", 0) pframe_out = previous_data.get("frame_in", 0) name = data.get("name", "") pname = previous_shot["name"] version = None if frame_in != pframe_in or frame_out != pframe_out or name != pname: current_user_id = persons_service.get_current_user()["id"] previous_updated_at = fields.get_date_object( previous_shot["updated_at"], date_format="%Y-%m-%dT%H:%M:%S" ) updated_at = fields.get_date_object( shot["updated_at"], date_format="%Y-%m-%dT%H:%M:%S" ) if ( date_helpers.get_date_diff(previous_updated_at, updated_at) > 60 ): version = EntityVersion.create( entity_id=shot["id"], name=pname, data=shot["data"], person_id=current_user_id, ) return version
def get_shot_versions(shot_id): """ Shot metadata changes are versioned. This function returns all versions of a given shot. """ versions = (EntityVersion.query.filter_by(entity_id=shot_id).order_by( EntityVersion.created_at.desc()).all()) return EntityVersion.serialize_list(versions, obj_type="ShotVersion")
def remove_edit(edit_id, force=False): """ Remove given edit from database. If it has tasks linked to it, it marks the edit as canceled. Deletion can be forced. """ edit = get_edit_raw(edit_id) is_tasks_related = Task.query.filter_by(entity_id=edit_id).count() > 0 if is_tasks_related and not force: edit.update({"canceled": True}) clear_edit_cache(edit_id) events.emit( "edit:update", {"edit_id": edit_id}, project_id=str(edit.project_id), ) else: from zou.app.services import tasks_service tasks = Task.query.filter_by(entity_id=edit_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=edit_id) Subscription.delete_all_by(entity_id=edit_id) EntityLink.delete_all_by(entity_in_id=edit_id) edit.delete() clear_edit_cache(edit_id) events.emit( "edit:delete", {"edit_id": edit_id}, project_id=str(edit.project_id), ) deleted_edit = edit.serialize(obj_type="Edit") return deleted_edit
def save_version_if_needed(self, shot, previous_shot): previous_data = previous_shot.get("data", {}) or {} data = shot.get("data", {}) frame_in = data.get("frame_in", 0) pframe_in = previous_data.get("frame_in", 0) frame_out = data.get("frame_in", 0) pframe_out = previous_data.get("frame_in", 0) name = data.get("name", "") pname = previous_shot["name"] version = None if frame_in != pframe_in or frame_out != pframe_out or name != pname: version = EntityVersion.create( entity_id=shot["id"], name=pname, data=previous_data ) return version