diff --git a/partitioncloud/modules/admin.py b/partitioncloud/modules/admin.py index 1ef1781..0ce16c4 100644 --- a/partitioncloud/modules/admin.py +++ b/partitioncloud/modules/admin.py @@ -27,7 +27,6 @@ def index(): for u in users: u.albums = u.get_albums() u.partitions = u.get_partitions() - db.close() return render_template( "admin/index.html", diff --git a/partitioncloud/modules/albums.py b/partitioncloud/modules/albums.py index 91f2eb8..c4691ef 100644 --- a/partitioncloud/modules/albums.py +++ b/partitioncloud/modules/albums.py @@ -171,10 +171,10 @@ def join_album(uuid): user.join_album(uuid) except LookupError: flash("Cet album n'existe pas.") - return redirect(f"/albums/{uuid}") + return redirect(request.referrer) flash("Album ajouté à la collection.") - return redirect(f"/albums/{uuid}") + return redirect(request.referrer) @bp.route("//quit") @@ -185,7 +185,7 @@ def quit_album(uuid): users = album.get_users() if user.id not in [u["id"] for u in users]: flash("Vous ne faites pas partie de cet album") - return redirect(f"/albums/{uuid}") + return redirect(request.referrer) if len(users) == 1: 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: flash(error) - return redirect(f"/albums/{uuid}") + return redirect(request.referrer) album.delete() @@ -236,7 +236,7 @@ def add_partition(album_uuid): if (not user.is_participant(album.uuid)) and (user.access_level != 1): flash("Vous ne participez pas à cet album.") - return redirect(f"/albums/{album.uuid}") + return redirect(request.referrer) error = None @@ -264,7 +264,7 @@ def add_partition(album_uuid): if error is not None: flash(error) - return redirect(f"/albums/{album.uuid}") + return redirect(request.referrer) if "author" in request.form: author = request.form["author"] @@ -318,7 +318,7 @@ def add_partition(album_uuid): pass flash(f"Partition {request.form['name']} ajoutée") - return redirect(f"/albums/{album.uuid}") + return redirect(request.referrer) @bp.route("/add-partition", methods=["POST"]) diff --git a/partitioncloud/modules/auth.py b/partitioncloud/modules/auth.py index ad2bc01..da24e80 100644 --- a/partitioncloud/modules/auth.py +++ b/partitioncloud/modules/auth.py @@ -123,7 +123,6 @@ def register(): return redirect(url_for("auth.login")) flash(error) - db.close() return render_template("auth/register.html") diff --git a/partitioncloud/modules/classes/album.py b/partitioncloud/modules/classes/album.py index 966a7df..5d3c884 100644 --- a/partitioncloud/modules/classes/album.py +++ b/partitioncloud/modules/classes/album.py @@ -41,20 +41,22 @@ class Album(): self.users = None - def get_users(self): + def get_users(self, force_reload=False): """ Renvoie les utilisateurs liés à l'album """ - db = get_db() - return db.execute( - """ - SELECT * FROM user - JOIN contient_user ON user_id = user.id - JOIN album ON album.id = album_id - WHERE album.uuid = ? - """, - (self.uuid,) - ).fetchall() + if self.users is None or force_reload: + db = get_db() + self.users = db.execute( + """ + SELECT * FROM user + JOIN contient_user ON user_id = user.id + JOIN album ON album.id = album_id + WHERE album.uuid = ? + """, + (self.uuid,) + ).fetchall() + return self.users def get_partitions(self): """