def publisher_admin_images(self): self.meta_tags(title="Images") if request.method == "POST": id = request.form.get("id", None) action = request.form.get("action") description = request.form.get("description") if id: image = PostModel.UploadObject.get(id) if image: if action == "delete": image.delete() obj = storage.get(image.name) if obj: obj.delete() flash("Image deleted successfully!", "success") else: image.update(description=description) flash("Image updated successfully!", "success") else: abort(404, "No image ID provided") return redirect(url_for("PublisherAdmin:images")) else: page = request.args.get("page", 1) per_page = self.get_config("PAGINATION_PER_PAGE", 25) images = PostModel.UploadObject.all()\ .filter(PostModel.UploadObject.type == "IMAGE")\ .order_by(PostModel.UploadObject.name.asc()) images = images.paginate(page=page, per_page=per_page) return dict(images=images)
def upload(self): self.meta_tags(title="Upload Demo") if request.method == "POST": try: _file = request.files.get('file') if _file: my_object = storage.upload(_file, prefix="demo/", public=True, allowed_extensions=["gif", "jpg", "jpeg", "png"]) if my_object: return redirect(url_for("Account:upload", object_name=my_object.name)) except Exception as e: flash_error(e.message) return redirect(url_for("Account:upload")) my_object = None object_name = request.args.get("object_name") if object_name: my_object = storage.get(object_name=object_name) return {"my_object": my_object}