def edit_page(id): """ Returns: """ form = PageEditorForm() form.id = id page = Page() page_element = PageElement() form.parent_id.choices = page.get_id_label_list() page_elements = list() if id > 0: page.set_id(id) page.load() page_elements = page_element.get_list_for_page(page.get_id()) if request.method == "POST": if form.validate_on_submit(): page.prepare_form_input(request.form) page.save() page.load() else: form.get_error_messages() form.init_values(page) return render_template("content/pages/edit_page.html", form=form, page_elements=page_elements)
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 delete_page(id): """ Returns: """ if id > 0: page = Page() page.set_id(id) page.load() page.delete() return redirect(url_for("backend.pages"))