def image_upload(): """ Returns: """ try: if "file" in request.files: file = request.files["file"] if file and allowed_file(file.filename): filename = secure_filename(file.filename) id = escape(request.form["id"]) type = escape(request.form["type"]) module = escape(request.form["module"]) max_files = escape(request.form["max_files"]) max_size = escape(request.form["max_size"]) image_format = escape(request.form["image_format"]) """ z.B: ein page objekt erzeugen die id setzen und laden anhand von max_files prüfen ob eine liste benötigt wird wenn ja bild hinzufügen. andernfalls mit image_format einfach nur dem wert im dataitem setzen """ if module == "pages": module_object = Page() module_object.set_id(id) module_object.load() base_path = current_app.config["ROOT_DIR"] + "app/static/" final_upload_path = base_path + type + "/" + module + "/" + id + "/" if not os.path.isdir(final_upload_path): os.makedirs(final_upload_path) final_path = os.path.join(final_upload_path, filename) if int(max_files) > 1: current_data = module_object.get_list_or_dict(image_format) if len(current_data) < max_files: module_object.add(image_format, final_path) else: return make_response(400) else: module_object.set(image_format, final_path) file.save(final_path) module_object.save() return filename return make_response(500) except Exception as error: print(error)
def add_page(): """ Returns: """ form = PageEditorForm() page = Page() page.init_default() page.set("ctrl_template", "standard") page.set("ctrl_index", 1) page.save() return render_template("content/pages/add_page.html", form=form, form_object=page)