A bunch of small fixes

This commit is contained in:
augustin64 2023-10-11 15:57:06 +02:00
parent a65a80cd8b
commit 3f68ac0419
4 changed files with 20 additions and 20 deletions

View File

@ -27,7 +27,6 @@ def index():
for u in users: for u in users:
u.albums = u.get_albums() u.albums = u.get_albums()
u.partitions = u.get_partitions() u.partitions = u.get_partitions()
db.close()
return render_template( return render_template(
"admin/index.html", "admin/index.html",

View File

@ -171,10 +171,10 @@ def join_album(uuid):
user.join_album(uuid) user.join_album(uuid)
except LookupError: except LookupError:
flash("Cet album n'existe pas.") flash("Cet album n'existe pas.")
return redirect(f"/albums/{uuid}") return redirect(request.referrer)
flash("Album ajouté à la collection.") flash("Album ajouté à la collection.")
return redirect(f"/albums/{uuid}") return redirect(request.referrer)
@bp.route("/<uuid>/quit") @bp.route("/<uuid>/quit")
@ -185,7 +185,7 @@ def quit_album(uuid):
users = album.get_users() users = album.get_users()
if user.id not in [u["id"] for u in users]: if user.id not in [u["id"] for u in users]:
flash("Vous ne faites pas partie de cet album") flash("Vous ne faites pas partie de cet album")
return redirect(f"/albums/{uuid}") return redirect(request.referrer)
if len(users) == 1: if len(users) == 1:
flash("Vous êtes seul dans cet album, le quitter entraînera sa suppression.") flash("Vous êtes seul dans cet album, le quitter entraînera sa suppression.")
@ -218,7 +218,7 @@ def delete_album(uuid):
if error is not None: if error is not None:
flash(error) flash(error)
return redirect(f"/albums/{uuid}") return redirect(request.referrer)
album.delete() album.delete()
@ -236,7 +236,7 @@ def add_partition(album_uuid):
if (not user.is_participant(album.uuid)) and (user.access_level != 1): if (not user.is_participant(album.uuid)) and (user.access_level != 1):
flash("Vous ne participez pas à cet album.") flash("Vous ne participez pas à cet album.")
return redirect(f"/albums/{album.uuid}") return redirect(request.referrer)
error = None error = None
@ -264,7 +264,7 @@ def add_partition(album_uuid):
if error is not None: if error is not None:
flash(error) flash(error)
return redirect(f"/albums/{album.uuid}") return redirect(request.referrer)
if "author" in request.form: if "author" in request.form:
author = request.form["author"] author = request.form["author"]
@ -318,7 +318,7 @@ def add_partition(album_uuid):
pass pass
flash(f"Partition {request.form['name']} ajoutée") flash(f"Partition {request.form['name']} ajoutée")
return redirect(f"/albums/{album.uuid}") return redirect(request.referrer)
@bp.route("/add-partition", methods=["POST"]) @bp.route("/add-partition", methods=["POST"])

View File

@ -123,7 +123,6 @@ def register():
return redirect(url_for("auth.login")) return redirect(url_for("auth.login"))
flash(error) flash(error)
db.close()
return render_template("auth/register.html") return render_template("auth/register.html")

View File

@ -41,20 +41,22 @@ class Album():
self.users = None self.users = None
def get_users(self): def get_users(self, force_reload=False):
""" """
Renvoie les utilisateurs liés à l'album Renvoie les utilisateurs liés à l'album
""" """
db = get_db() if self.users is None or force_reload:
return db.execute( db = get_db()
""" self.users = db.execute(
SELECT * FROM user """
JOIN contient_user ON user_id = user.id SELECT * FROM user
JOIN album ON album.id = album_id JOIN contient_user ON user_id = user.id
WHERE album.uuid = ? JOIN album ON album.id = album_id
""", WHERE album.uuid = ?
(self.uuid,) """,
).fetchall() (self.uuid,)
).fetchall()
return self.users
def get_partitions(self): def get_partitions(self):
""" """