def put(self, id): args = file_upload.parse_args() logger.warning("Ignoring files via args! (using JSON body)", args=args) item = load(Kind, id) # todo: raise 404 o abort data = request.get_json() kind_update = {} image_cols = [ "image_1", "image_2", "image_3", "image_4", "image_5", "image_6" ] for image_col in image_cols: if data.get(image_col) and type(data[image_col]) == dict: name = name_file(image_col, item.name, getattr(item, image_col)) upload_file(data[image_col]["src"], name) # todo: use mime-type in first part of kind_update[image_col] = name if kind_update: kind_update["complete"] = (True if data.get("image_1") and item.description_nl and item.description_en else False) kind_update["modified_at"] = datetime.utcnow() item = update(item, kind_update) return item, 201
def patch(self, id): item = load(Order, id) if ("complete" not in item.status and api.payload.get("status") and (api.payload["status"] == "complete" or api.payload["status"] == "cancelled") and not item.completed_at): item.completed_at = datetime.datetime.utcnow() item.completed_by = current_user.id _ = update(item, api.payload) return "", 204
def put(self, id): """Edit Order""" item = load(Order, id) if (api.payload.get("status") and (api.payload["status"] == "completed" or api.payload["status"] == "cancelled") and not item.completed_at): item.completed_at = datetime.datetime.utcnow() item.completed_by = current_user.id item = update(item, api.payload) return item, 201
def put(self, id): """Edit Kind""" item = load(Kind, id) if api.payload.get("approved"): if api.payload["approved"] and not item.approved: api.payload["approved_at"] = datetime.utcnow() if not api.payload["approved"] and item.approved: api.payload["approved_at"] = None api.payload["complete"] = ( True if item.image_1 and api.payload.get("description_nl") and api.payload.get("description_en") else False ) item = update(item, api.payload) return item, 201
def put(self, id): """Edit ShopToPrice""" item = load(ShopToPrice, id) # Todo increase validation -> if the update is correct price = Price.query.filter(Price.id == api.payload["price_id"]).first() shop = Shop.query.filter(Shop.id == api.payload["shop_id"]).first() kind = Kind.query.filter(Kind.id == api.payload["kind_id"]).first() product = Product.query.filter( Product.id == api.payload["product_id"]).first() if not price or not shop: abort(400, "Price or Shop not found") if (product and kind) or not product and not kind: abort(400, "One Cannabis or one Horeca product has to be provided") # Ok we survived all that: let's save it: item = update(item, api.payload) invalidateShopCache(item.shop_id) return item, 201
def put(self, id): args = file_upload.parse_args() logger.warning("Ignoring files via args! (using JSON body)", args=args) item = load(BackingTrack, id) api.payload["modified_at"] = datetime.datetime.utcnow() if api.payload.get("approved"): if api.payload["approved"] and not item.approved: api.payload["approved_at"] = datetime.datetime.utcnow() if not api.payload["approved"] and item.approved: api.payload["approved_at"] = None data = request.get_json() backing_track_update = {} file_cols = ["file"] for file_col in file_cols: if data.get(file_col) and type(data[file_col]) == dict: name = f"{uuid.uuid4()}.mp3" upload_file(data[file_col]["src"], name) backing_track_update[file_col] = name item = update(item, {**api.payload, **backing_track_update}) return item, 201
def put(self, id): """Edit Tag""" item = load(Riff, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit Flavor""" item = load(Flavor, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit Strain""" item = load(Strain, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit Price""" item = load(Price, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit MainCategory""" item = load(MainCategory, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit ExerciseToTag""" item = load(RiffExerciseTag, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit Shop""" item = load(Shop, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit KindToTag""" item = load(KindToTag, id) item = update(item, api.payload) return item, 201
def put(self, id): """Edit Table""" item = load(Table, id) item = update(item, api.payload) return item, 201