From b86c7322dc7c5383572fe59769bcfc67756b91e9 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 17 Jun 2023 21:25:13 +0200 Subject: [PATCH] Add create-album dialog --- partitioncloud/modules/albums.py | 69 +++++++++---------- partitioncloud/static/style.css | 34 +++++++-- .../templates/albums/create-album.html | 13 ---- partitioncloud/templates/base.html | 35 +++++++++- 4 files changed, 92 insertions(+), 59 deletions(-) delete mode 100644 partitioncloud/templates/albums/create-album.html diff --git a/partitioncloud/modules/albums.py b/partitioncloud/modules/albums.py index 6096292..805b8fb 100644 --- a/partitioncloud/modules/albums.py +++ b/partitioncloud/modules/albums.py @@ -118,52 +118,49 @@ def partition(album_uuid, partition_uuid): ) -@bp.route("/create-album", methods=["GET", "POST"]) +@bp.route("/create-album", methods=["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() - error = None + name = request.form["name"] + db = get_db() + error = None - if not name or name.strip() == "": - error = "Un nom est requis." + if not name or name.strip() == "": + error = "Un nom est requis. L'album n'a pas été créé" - if error is None: - while True: - try: - uuid = str(uuid4()) + if error is None: + while True: + try: + uuid = str(uuid4()) - db.execute( - """ - INSERT INTO album (uuid, name) - VALUES (?, ?) - """, - (uuid, name), - ) - db.commit() - album = Album(uuid=uuid) - db.execute( - """ - INSERT INTO contient_user (user_id, album_id) - VALUES (?, ?) - """, - (session.get("user_id"), album.id), - ) - db.commit() + db.execute( + """ + INSERT INTO album (uuid, name) + VALUES (?, ?) + """, + (uuid, name), + ) + db.commit() + album = Album(uuid=uuid) + db.execute( + """ + INSERT INTO contient_user (user_id, album_id) + VALUES (?, ?) + """, + (session.get("user_id"), album.id), + ) + db.commit() - break - except db.IntegrityError: - pass + break + except db.IntegrityError: + pass - return redirect(f"/albums/{uuid}") + return redirect(f"/albums/{uuid}") - flash(error) - return render_template("albums/create-album.html", user=current_user) - - return render_template("albums/create-album.html", user=current_user) + flash(error) + return redirect(request.referrer) @bp.route("//join") diff --git a/partitioncloud/static/style.css b/partitioncloud/static/style.css index f935924..f7f19df 100644 --- a/partitioncloud/static/style.css +++ b/partitioncloud/static/style.css @@ -1,11 +1,11 @@ -@import url('https://augustin64.fr/static/font/iosevka.css'); +@import url('https://www.augustin64.fr/static/font/iosevka.css'); /** Color Schemes */ /* Themes used: Catppuccin Latte & Moccha * https://github.com/catppuccin/catppuccin */ -/* Light theme : catppuccin Latte */ +/* Dark theme: Catpuccin Mocha */ :root { --color-rosewater: #f5e0dc; --color-flamingo: #f2cdcd; @@ -37,7 +37,7 @@ --font-family: Iosevka Web; } -/* Dark theme: Catpuccin Mocha */ +/* Light theme: Catppuccin Latte */ @media (prefers-color-scheme: light) { :root { --color-rosewater: #dc8a78; @@ -78,10 +78,14 @@ /** Generic things */ -h1 { +h1, #sidebar>h2 { margin-left: 30px; } +h2 { + color: var(--color-subtext1); +} + a { text-decoration: none; color: var(--color-blue); @@ -269,10 +273,26 @@ img.partition-thumbnail { background-color: var(--color-blue); } -/** Sidebar: "settings" */ +/** Sidebar content */ +#new-album-button { + text-align: center; + margin: 10px; + background-color: var(--color-surface1); + padding: 8px 0; + border-radius: 5px; + color: var(--color-text); + border: 2px solid var(--color-overlay0); +} + +#new-album-button:hover { + border-color: var(--color-blue); + background-color: var(--color-surface0); +} + #albums { overflow: scroll; height: 70vh; + padding: 0 5px; } #albums div { @@ -324,11 +344,11 @@ button#logout, a#delete-album { color: var(--color-red); } -button#logout>svg { +#settings-container svg.icon { scale: 0.9; position: absolute; - top: 7px; left: 10px; + transform: translateY(-17%); } #settings-container>.user { diff --git a/partitioncloud/templates/albums/create-album.html b/partitioncloud/templates/albums/create-album.html deleted file mode 100644 index 2d620a0..0000000 --- a/partitioncloud/templates/albums/create-album.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends 'base.html' %} - -{% block header %} -

{% block title %}Nouvel Album{% endblock %}

-{% endblock %} - -{% block content %} -
- - - -
-{% endblock %} \ No newline at end of file diff --git a/partitioncloud/templates/base.html b/partitioncloud/templates/base.html index d9da290..21dd703 100644 --- a/partitioncloud/templates/base.html +++ b/partitioncloud/templates/base.html @@ -18,6 +18,16 @@ {% block dialogs %}{% endblock %} + {% if g.user %} + +

Créer un nouvel album

+
+
+ +
+ Close +
+ {% endif %}
@@ -48,7 +58,14 @@ {% endif %} -

Albums

+

Albums

+ {% if g.user %} + +
+ Créer un album +
+
+ {% endif %}
{% if not g.user %}
Connectez vous pour avoir accès à vos albums
@@ -69,7 +86,7 @@ {% if g.user %}
{% if g.user.access_level == 1 %} -
+
{% endif %}