roundabout,
created on Monday, 9 September 2024, 14:17:24 (1725891444),
received on Tuesday, 10 September 2024, 13:58:09 (1725976689)
Author identity: vlad <vlad.muntoiu@gmail.com>
f11f5bed3492ac38a7d45ce9b6646fd819b21d38
app.py
@@ -591,6 +591,7 @@ def delete_picture(id):
PictureLicence.query.filter_by(resource=resource).delete() PictureRegion.query.filter_by(resource=resource).delete() PictureInGallery.query.filter_by(resource=resource).delete()if resource.replaces: resource.replaces.replaced_by = None if resource.replaced_by:
@@ -758,7 +759,11 @@ def gallery(id):
if gallery is None: flask.abort(404) return flask.render_template("gallery.html", gallery=gallery)current_user = db.session.get(User, flask.session.get("username")) have_permission = current_user and (current_user == gallery.owner or current_user.admin) return flask.render_template("gallery.html", gallery=gallery, have_permission=have_permission)@app.route("/create-gallery")
@@ -824,6 +829,37 @@ def gallery_add_picture(id):
return flask.redirect("/gallery/" + str(gallery.id)) @app.route("/gallery/<int:id>/remove-picture", methods=["POST"]) def gallery_remove_picture(id): gallery = db.session.get(Gallery, id) if gallery is None: flask.abort(404) if "username" not in flask.session: flask.abort(401) if flask.session["username"] != gallery.owner_name and not db.session.get(User, flask.session["username"]).admin: flask.abort(403) picture_id = int(flask.request.form.get("picture_id")) picture = db.session.get(PictureResource, picture_id) if picture is None: flask.flash("Invalid picture") return flask.redirect("/gallery/" + str(gallery.id)) picture_in_gallery = PictureInGallery.query.filter_by(resource=picture, gallery=gallery).first() if picture_in_gallery is None: flask.flash("This picture isn't in the gallery") return flask.redirect("/gallery/" + str(gallery.id)) db.session.delete(picture_in_gallery) db.session.commit() return flask.redirect("/gallery/" + str(gallery.id)) def get_picture_query(query_data): query = db.session.query(PictureResource)
templates/gallery.html
@@ -6,10 +6,12 @@
<x-frame style="--width: 768px" class="vbox"> <h1>{{ gallery.title }}</h1> <p>{{ gallery.description }}</p> <form class="buttonbox" method="POST" action="/gallery/{{ gallery.id }}/add-picture"><input name="picture_id" type="text" placeholder="Picture ID" required aria-label="Picture ID"><button type="submit">Add picture</button></form>{% if have_permission %} <form class="buttonbox" method="POST" action="/gallery/{{ gallery.id }}/add-picture"> <input name="picture_id" type="text" placeholder="Picture ID" required aria-label="Picture ID"> <button type="submit">Add picture</button> </form> {% endif %}<h2>Pictures</h2> <ul class="thumbnail-list"> {% for picture in gallery.pictures %}
@@ -46,6 +48,12 @@
{{ picture.resource.title }} </div> </a> <div class="list-more"> <form action="/gallery/{{ gallery.id }}/remove-picture" method="POST"> <input type="hidden" name="picture_id" value="{{ picture.resource.id }}"> <button type="submit" class="button-flat">Remove</button> </form> </div></li> {% endfor %} </ul>