mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 09:16:25 +01:00
Pass current user to every render_template
This commit is contained in:
parent
f73e5bbd42
commit
b5d83e3c50
@ -41,6 +41,8 @@ def add_user():
|
||||
"""
|
||||
Ajouter un utilisateur en tant qu'administrateur
|
||||
"""
|
||||
current_user = User(user_id=session.get("user_id"))
|
||||
|
||||
if request.method == "POST":
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
@ -77,7 +79,7 @@ def add_user():
|
||||
return redirect("/albums")
|
||||
|
||||
flash(error)
|
||||
return render_template("auth/register.html", albums=get_all_albums())
|
||||
return render_template("auth/register.html", albums=get_all_albums(), user=current_user)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -15,6 +15,7 @@ bp = Blueprint("admin", __name__, url_prefix="/admin")
|
||||
@bp.route("/")
|
||||
@admin_required
|
||||
def index():
|
||||
current_user = User(user_id=session.get("user_id"))
|
||||
db = get_db()
|
||||
users_id = db.execute(
|
||||
"""
|
||||
@ -29,5 +30,6 @@ def index():
|
||||
|
||||
return render_template(
|
||||
"admin/index.html",
|
||||
users=users
|
||||
users=users,
|
||||
user=current_user
|
||||
)
|
@ -28,7 +28,7 @@ def index():
|
||||
else:
|
||||
max_queries = current_app.config["MAX_ONLINE_QUERIES"]
|
||||
|
||||
return render_template("albums/index.html", albums=albums, MAX_QUERIES=max_queries)
|
||||
return render_template("albums/index.html", user=user)
|
||||
|
||||
|
||||
@bp.route("/search", methods=["POST"])
|
||||
@ -54,12 +54,14 @@ def search_page():
|
||||
else:
|
||||
google_results = []
|
||||
|
||||
user.get_albums()
|
||||
|
||||
return render_template(
|
||||
"albums/search.html",
|
||||
partitions=partitions_local,
|
||||
google_results=google_results,
|
||||
query=query,
|
||||
albums=user.get_albums()
|
||||
user=user
|
||||
)
|
||||
|
||||
@bp.route("/<uuid>")
|
||||
@ -82,7 +84,8 @@ def album(uuid):
|
||||
"albums/album.html",
|
||||
album=album,
|
||||
partitions=partitions,
|
||||
not_participant=not_participant
|
||||
not_participant=not_participant,
|
||||
user=user
|
||||
)
|
||||
|
||||
except LookupError:
|
||||
@ -118,6 +121,8 @@ def partition(album_uuid, partition_uuid):
|
||||
@bp.route("/create-album", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def create_album():
|
||||
current_user = User(user_id=session.get("user_id"))
|
||||
|
||||
if request.method == "POST":
|
||||
name = request.form["name"]
|
||||
db = get_db()
|
||||
@ -156,9 +161,9 @@ def create_album():
|
||||
return redirect(f"/albums/{uuid}")
|
||||
|
||||
flash(error)
|
||||
return render_template("albums/create-album.html")
|
||||
return render_template("albums/create-album.html", user=current_user)
|
||||
|
||||
return render_template("albums/create-album.html")
|
||||
return render_template("albums/create-album.html", user=current_user)
|
||||
|
||||
|
||||
@bp.route("/<uuid>/join")
|
||||
@ -199,13 +204,13 @@ def quit_album(uuid):
|
||||
def delete_album(uuid):
|
||||
db = get_db()
|
||||
album = Album(uuid=uuid)
|
||||
user = User(user_id=session.get("user_id"))
|
||||
|
||||
if request.method == "GET":
|
||||
return render_template("albums/delete-album.html", album=album)
|
||||
return render_template("albums/delete-album.html", album=album, user=user)
|
||||
|
||||
error = None
|
||||
users = album.get_users()
|
||||
user = User(user_id=session.get("user_id"))
|
||||
if len(users) > 1:
|
||||
error = "Vous n'êtes pas seul dans cet album."
|
||||
elif len(users) == 1 and users[0]["id"] != user.id:
|
||||
@ -236,7 +241,7 @@ def add_partition(album_uuid):
|
||||
return redirect(f"/albums/{album.uuid}")
|
||||
|
||||
if request.method == "GET":
|
||||
return render_template("albums/add-partition.html", album=album)
|
||||
return render_template("albums/add-partition.html", album=album, user=user)
|
||||
|
||||
error = None
|
||||
|
||||
@ -362,7 +367,8 @@ def add_partition_from_search():
|
||||
return render_template(
|
||||
"albums/add-partition.html",
|
||||
album=album,
|
||||
partition_uuid=request.form["partition-uuid"]
|
||||
partition_uuid=request.form["partition-uuid"],
|
||||
user=user
|
||||
)
|
||||
|
||||
else:
|
||||
|
@ -46,7 +46,7 @@ def edit(uuid):
|
||||
return redirect("/albums")
|
||||
|
||||
if request.method == "GET":
|
||||
return render_template("partition/edit.html", partition=partition)
|
||||
return render_template("partition/edit.html", partition=partition, user=user)
|
||||
|
||||
error = None
|
||||
|
||||
@ -90,8 +90,9 @@ def details(uuid):
|
||||
return render_template(
|
||||
"partition/details.html",
|
||||
partition=partition,
|
||||
user=partition_user,
|
||||
albums=partition.get_albums()
|
||||
partition_user=partition_user,
|
||||
albums=partition.get_albums(),
|
||||
user=user
|
||||
)
|
||||
|
||||
error = None
|
||||
@ -132,7 +133,7 @@ def delete(uuid):
|
||||
return redirect("/albums")
|
||||
|
||||
if request.method == "GET":
|
||||
return render_template("partition/delete.html", partition=partition)
|
||||
return render_template("partition/delete.html", partition=partition, user=user)
|
||||
|
||||
partition.delete()
|
||||
|
||||
@ -163,4 +164,5 @@ def partition_search(uuid):
|
||||
@admin_required
|
||||
def index():
|
||||
partitions = get_all_partitions()
|
||||
return render_template("admin/partitions.html", partitions=partitions)
|
||||
user = User(user_id=session.get("user_id"))
|
||||
return render_template("admin/partitions.html", partitions=partitions, user=user)
|
Loading…
Reference in New Issue
Block a user