From fdcda1b5669e9e01dc61984c3e6d1866b0491a83 Mon Sep 17 00:00:00 2001 From: marc Date: Sun, 21 Dec 2025 17:09:59 +0100 Subject: [PATCH] =?UTF-8?q?Nova=20p=C3=A0gina=20de=20llistes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- folkugat_web/api/routes/__init__.py | 3 +- folkugat_web/api/routes/llista/playlist.py | 20 ++++++++ folkugat_web/api/routes/llistes/__init__.py | 5 ++ folkugat_web/api/routes/llistes/index.py | 26 +++++++++++ folkugat_web/assets/static/css/main.css | 17 +++++++ .../{playlist => llista}/editor/name.html | 0 .../fragments/{playlist => llista}/name.html | 1 + .../{playlist => llista}/pagina.html | 8 ++-- .../{playlist => llista}/playlist.html | 3 +- .../fragments/{playlist => llista}/score.html | 0 .../fragments/llista/set/pagina.html | 2 + .../{playlist => llista}/set/set_page.html | 6 +-- .../{playlist => llista}/set/set_score.html | 0 .../{playlist => llista}/set/tema.html | 2 +- .../{playlist => llista}/set/tema_title.html | 0 .../{playlist => llista}/set_entry.html | 4 +- .../{playlist => llista}/tema_editor.html | 0 .../{playlist => llista}/tema_entry.html | 0 .../{playlist => llista}/tema_results.html | 0 .../fragments/llista/visibility.html | 15 ++++++ .../templates/fragments/llistes/pagina.html | 16 +++++++ .../fragments/llistes/playlist_entry.html | 24 ++++++++++ .../assets/templates/fragments/menu.html | 13 ++++++ .../fragments/playlist/set/pagina.html | 2 - .../templates/fragments/sessio/pagina.html | 4 +- folkugat_web/dal/sql/playlists/conversion.py | 11 ++++- folkugat_web/dal/sql/playlists/ddl.py | 5 +- folkugat_web/dal/sql/playlists/query.py | 32 +++++++++++++ folkugat_web/dal/sql/playlists/write.py | 17 +++++++ folkugat_web/fragments/__init__.py | 1 + folkugat_web/fragments/llistes.py | 17 +++++++ folkugat_web/fragments/playlist.py | 31 +++++++++---- folkugat_web/fragments/set_page.py | 6 +-- folkugat_web/model/pagines.py | 1 + folkugat_web/model/playlists.py | 1 + folkugat_web/services/playlists.py | 17 +++++++ scripts/07_add_playlist_hidden.py | 46 +++++++++++++++++++ 37 files changed, 323 insertions(+), 33 deletions(-) create mode 100644 folkugat_web/api/routes/llistes/__init__.py create mode 100644 folkugat_web/api/routes/llistes/index.py rename folkugat_web/assets/templates/fragments/{playlist => llista}/editor/name.html (100%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/name.html (91%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/pagina.html (57%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/playlist.html (87%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/score.html (100%) create mode 100644 folkugat_web/assets/templates/fragments/llista/set/pagina.html rename folkugat_web/assets/templates/fragments/{playlist => llista}/set/set_page.html (87%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/set/set_score.html (100%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/set/tema.html (89%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/set/tema_title.html (100%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/set_entry.html (94%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/tema_editor.html (100%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/tema_entry.html (100%) rename folkugat_web/assets/templates/fragments/{playlist => llista}/tema_results.html (100%) create mode 100644 folkugat_web/assets/templates/fragments/llista/visibility.html create mode 100644 folkugat_web/assets/templates/fragments/llistes/pagina.html create mode 100644 folkugat_web/assets/templates/fragments/llistes/playlist_entry.html delete mode 100644 folkugat_web/assets/templates/fragments/playlist/set/pagina.html create mode 100644 folkugat_web/fragments/llistes.py create mode 100644 scripts/07_add_playlist_hidden.py diff --git a/folkugat_web/api/routes/__init__.py b/folkugat_web/api/routes/__init__.py index e3b64eb..a0cfe8a 100644 --- a/folkugat_web/api/routes/__init__.py +++ b/folkugat_web/api/routes/__init__.py @@ -1,12 +1,13 @@ from folkugat_web.api.router import get_router -from . import auth, index, llista, sessio, sessions, tema, temes +from . import auth, index, llista, llistes, sessio, sessions, tema, temes router = get_router() router.include_router(auth.router) router.include_router(index.router) router.include_router(llista.router) +router.include_router(llistes.router) router.include_router(sessio.router) router.include_router(sessions.router) router.include_router(tema.router) diff --git a/folkugat_web/api/routes/llista/playlist.py b/folkugat_web/api/routes/llista/playlist.py index cc50e98..388dfac 100644 --- a/folkugat_web/api/routes/llista/playlist.py +++ b/folkugat_web/api/routes/llista/playlist.py @@ -247,3 +247,23 @@ def set_tema_new( entry_id=entry_id, tema_id=new_tema.id, ) + + +@router.put("/api/llista/{playlist_id}/visible") +def set_visible(request: Request, logged_in: auth.RequireLogin, playlist_id: int): + new_playlist = playlists_service.set_visibility(playlist_id=playlist_id, hidden=False) + return playlist.visibility( + request=request, + logged_in=logged_in, + playlist=new_playlist, + ) + + +@router.put("/api/llista/{playlist_id}/invisible") +def set_invisible(request: Request, logged_in: auth.RequireLogin, playlist_id: int): + new_playlist = playlists_service.set_visibility(playlist_id=playlist_id, hidden=True) + return playlist.visibility( + request=request, + logged_in=logged_in, + playlist=new_playlist, + ) diff --git a/folkugat_web/api/routes/llistes/__init__.py b/folkugat_web/api/routes/llistes/__init__.py new file mode 100644 index 0000000..bd52a6d --- /dev/null +++ b/folkugat_web/api/routes/llistes/__init__.py @@ -0,0 +1,5 @@ +from folkugat_web.api.router import get_router +from . import index + +router = get_router() +router.include_router(index.router) \ No newline at end of file diff --git a/folkugat_web/api/routes/llistes/index.py b/folkugat_web/api/routes/llistes/index.py new file mode 100644 index 0000000..cbb3734 --- /dev/null +++ b/folkugat_web/api/routes/llistes/index.py @@ -0,0 +1,26 @@ +from fastapi import Request +from folkugat_web.api.router import get_router +from folkugat_web.fragments import llistes +from folkugat_web.services import auth +from folkugat_web.templates import templates + +router = get_router() + + +@router.get("/llistes") +def page(request: Request, logged_in: auth.LoggedIn): + return templates.TemplateResponse( + "index.html", + { + "request": request, + "page_title": "Folkugat", + "content": "/api/content/llistes", + "logged_in": logged_in, + "animate": False, + } + ) + + +@router.get("/api/content/llistes") +def content(request: Request, logged_in: auth.LoggedIn): + return llistes.llistes_pagina(request, logged_in) diff --git a/folkugat_web/assets/static/css/main.css b/folkugat_web/assets/static/css/main.css index 64e8a01..db51c08 100644 --- a/folkugat_web/assets/static/css/main.css +++ b/folkugat_web/assets/static/css/main.css @@ -899,6 +899,10 @@ video { justify-content: center; } +.justify-between { + justify-content: space-between; +} + .gap-2 { gap: 0.5rem; } @@ -1019,6 +1023,11 @@ video { padding-bottom: 1rem; } +.py-8 { + padding-top: 2rem; + padding-bottom: 2rem; +} + .pb-2 { padding-bottom: 0.5rem; } @@ -1085,6 +1094,10 @@ video { color: rgb(178 124 9 / var(--tw-text-opacity, 1)); } +.text-beige\/70 { + color: rgb(178 124 9 / 0.7); +} + .text-black { --tw-text-opacity: 1; color: rgb(0 0 0 / var(--tw-text-opacity, 1)); @@ -1134,6 +1147,10 @@ video { transition-duration: 200ms; } +.hover\:underline:hover { + text-decoration-line: underline; +} + .focus\:outline-none:focus { outline: 2px solid transparent; outline-offset: 2px; diff --git a/folkugat_web/assets/templates/fragments/playlist/editor/name.html b/folkugat_web/assets/templates/fragments/llista/editor/name.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/editor/name.html rename to folkugat_web/assets/templates/fragments/llista/editor/name.html diff --git a/folkugat_web/assets/templates/fragments/playlist/name.html b/folkugat_web/assets/templates/fragments/llista/name.html similarity index 91% rename from folkugat_web/assets/templates/fragments/playlist/name.html rename to folkugat_web/assets/templates/fragments/llista/name.html index 2c5bec7..ed77964 100644 --- a/folkugat_web/assets/templates/fragments/playlist/name.html +++ b/folkugat_web/assets/templates/fragments/llista/name.html @@ -15,5 +15,6 @@ hx-swap="outerHTML"> + {% include "fragments/llista/visibility.html" %} {% endif %} diff --git a/folkugat_web/assets/templates/fragments/playlist/pagina.html b/folkugat_web/assets/templates/fragments/llista/pagina.html similarity index 57% rename from folkugat_web/assets/templates/fragments/playlist/pagina.html rename to folkugat_web/assets/templates/fragments/llista/pagina.html index 585de39..0948653 100644 --- a/folkugat_web/assets/templates/fragments/playlist/pagina.html +++ b/folkugat_web/assets/templates/fragments/llista/pagina.html @@ -1,14 +1,14 @@ {% include "fragments/menu.html" %}
-
- {% include "fragments/playlist/name.html" %} +
+ {% include "fragments/llista/name.html" %}
- {% include "fragments/playlist/score.html" %}
{% set playlist_id = playlist.id %} {% set playlist = playlist %} - {% include "fragments/playlist/playlist.html" %} + {% include "fragments/llista/playlist.html" %}
+ {% include "fragments/llista/score.html" %}
diff --git a/folkugat_web/assets/templates/fragments/playlist/playlist.html b/folkugat_web/assets/templates/fragments/llista/playlist.html similarity index 87% rename from folkugat_web/assets/templates/fragments/playlist/playlist.html rename to folkugat_web/assets/templates/fragments/llista/playlist.html index 5726677..210dbbb 100644 --- a/folkugat_web/assets/templates/fragments/playlist/playlist.html +++ b/folkugat_web/assets/templates/fragments/llista/playlist.html @@ -1,8 +1,7 @@ {% if logged_in %}
diff --git a/folkugat_web/assets/templates/fragments/playlist/score.html b/folkugat_web/assets/templates/fragments/llista/score.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/score.html rename to folkugat_web/assets/templates/fragments/llista/score.html diff --git a/folkugat_web/assets/templates/fragments/llista/set/pagina.html b/folkugat_web/assets/templates/fragments/llista/set/pagina.html new file mode 100644 index 0000000..d0bbd4f --- /dev/null +++ b/folkugat_web/assets/templates/fragments/llista/set/pagina.html @@ -0,0 +1,2 @@ +{% include "fragments/menu.html" %} +{% include "fragments/llista/set/set_page.html" %} diff --git a/folkugat_web/assets/templates/fragments/playlist/set/set_page.html b/folkugat_web/assets/templates/fragments/llista/set/set_page.html similarity index 87% rename from folkugat_web/assets/templates/fragments/playlist/set/set_page.html rename to folkugat_web/assets/templates/fragments/llista/set/set_page.html index 1e05d00..8884b21 100644 --- a/folkugat_web/assets/templates/fragments/playlist/set/set_page.html +++ b/folkugat_web/assets/templates/fragments/llista/set/set_page.html @@ -13,14 +13,14 @@ {% for tema_in_set in set.temes %} {% if tema_in_set.tema is not none %} {% set tema = tema_in_set.tema %} - {% include "fragments/playlist/set/tema_title.html" %} + {% include "fragments/llista/set/tema_title.html" %} {% else %}

Desconegut

{% endif %} {% endfor %}

- {% include "fragments/playlist/set/set_score.html"%} + {% include "fragments/llista/set/set_score.html"%}
{% else %} {% for tema_in_set in set.temes %} @@ -31,7 +31,7 @@ {% endif %} {% if tema_in_set.tema is not none %} {% set tema = tema_in_set.tema %} - {% include "fragments/playlist/set/tema.html"%} + {% include "fragments/llista/set/tema.html"%} {% else %}

Desconegut diff --git a/folkugat_web/assets/templates/fragments/playlist/set/set_score.html b/folkugat_web/assets/templates/fragments/llista/set/set_score.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/set/set_score.html rename to folkugat_web/assets/templates/fragments/llista/set/set_score.html diff --git a/folkugat_web/assets/templates/fragments/playlist/set/tema.html b/folkugat_web/assets/templates/fragments/llista/set/tema.html similarity index 89% rename from folkugat_web/assets/templates/fragments/playlist/set/tema.html rename to folkugat_web/assets/templates/fragments/llista/set/tema.html index bc71a99..5f28a5e 100644 --- a/folkugat_web/assets/templates/fragments/playlist/set/tema.html +++ b/folkugat_web/assets/templates/fragments/llista/set/tema.html @@ -1,4 +1,4 @@ -{% include "fragments/playlist/set/tema_title.html" %} +{% include "fragments/llista/set/tema_title.html" %}
{% if tema.main_score() is not none %} diff --git a/folkugat_web/assets/templates/fragments/playlist/set/tema_title.html b/folkugat_web/assets/templates/fragments/llista/set/tema_title.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/set/tema_title.html rename to folkugat_web/assets/templates/fragments/llista/set/tema_title.html diff --git a/folkugat_web/assets/templates/fragments/playlist/set_entry.html b/folkugat_web/assets/templates/fragments/llista/set_entry.html similarity index 94% rename from folkugat_web/assets/templates/fragments/playlist/set_entry.html rename to folkugat_web/assets/templates/fragments/llista/set_entry.html index 015a1c3..1df2318 100644 --- a/folkugat_web/assets/templates/fragments/playlist/set_entry.html +++ b/folkugat_web/assets/templates/fragments/llista/set_entry.html @@ -36,9 +36,9 @@ hx-get="/api/llista/{{ playlist_id }}/set/{{ set_id }}" class="flex flex-col items-start w-full"> {% for tema_entry in set_entry.temes %} {% if new_entry %} - {% include "fragments/playlist/tema_editor.html" %} + {% include "fragments/llista/tema_editor.html" %} {% else %} - {% include "fragments/playlist/tema_entry.html" %} + {% include "fragments/llista/tema_entry.html" %} {% endif %} {% endfor %} diff --git a/folkugat_web/assets/templates/fragments/playlist/tema_editor.html b/folkugat_web/assets/templates/fragments/llista/tema_editor.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/tema_editor.html rename to folkugat_web/assets/templates/fragments/llista/tema_editor.html diff --git a/folkugat_web/assets/templates/fragments/playlist/tema_entry.html b/folkugat_web/assets/templates/fragments/llista/tema_entry.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/tema_entry.html rename to folkugat_web/assets/templates/fragments/llista/tema_entry.html diff --git a/folkugat_web/assets/templates/fragments/playlist/tema_results.html b/folkugat_web/assets/templates/fragments/llista/tema_results.html similarity index 100% rename from folkugat_web/assets/templates/fragments/playlist/tema_results.html rename to folkugat_web/assets/templates/fragments/llista/tema_results.html diff --git a/folkugat_web/assets/templates/fragments/llista/visibility.html b/folkugat_web/assets/templates/fragments/llista/visibility.html new file mode 100644 index 0000000..61b29e7 --- /dev/null +++ b/folkugat_web/assets/templates/fragments/llista/visibility.html @@ -0,0 +1,15 @@ +{% if not playlist.hidden %} + +{% else %} + +{% endif %} \ No newline at end of file diff --git a/folkugat_web/assets/templates/fragments/llistes/pagina.html b/folkugat_web/assets/templates/fragments/llistes/pagina.html new file mode 100644 index 0000000..d728386 --- /dev/null +++ b/folkugat_web/assets/templates/fragments/llistes/pagina.html @@ -0,0 +1,16 @@ +{% include "fragments/menu.html" %} +
+

Llistes de Repertori

+ + {% if playlists %} +
+ {% for playlist in playlists %} + {% include "fragments/llistes/playlist_entry.html" %} + {% endfor %} +
+ {% else %} +
+

No hi ha llistes disponibles.

+
+ {% endif %} +
diff --git a/folkugat_web/assets/templates/fragments/llistes/playlist_entry.html b/folkugat_web/assets/templates/fragments/llistes/playlist_entry.html new file mode 100644 index 0000000..138720f --- /dev/null +++ b/folkugat_web/assets/templates/fragments/llistes/playlist_entry.html @@ -0,0 +1,24 @@ +
+
+ + + {% if logged_in %} +
+ {% include "fragments/llista/visibility.html" %} +
+ {% endif %} +
+
diff --git a/folkugat_web/assets/templates/fragments/menu.html b/folkugat_web/assets/templates/fragments/menu.html index b8ac44b..2f7da85 100644 --- a/folkugat_web/assets/templates/fragments/menu.html +++ b/folkugat_web/assets/templates/fragments/menu.html @@ -27,6 +27,19 @@ + {% if menu_selected_id == Pages.Llistes %} +
  • + +
  • +
    {% set playlist_id = session.slowjam.id %} {% set playlist = session.slowjam %} - {% include "fragments/playlist/playlist.html" %} + {% include "fragments/llista/playlist.html" %}
    {% endif %} {% if logged_in or (session.setlist and session.setlist.sets) %} @@ -58,7 +58,7 @@

    {% set playlist_id = session.setlist.id %} {% set playlist = session.setlist %} - {% include "fragments/playlist/playlist.html" %} + {% include "fragments/llista/playlist.html" %}
    {% endif %}
    diff --git a/folkugat_web/dal/sql/playlists/conversion.py b/folkugat_web/dal/sql/playlists/conversion.py index a5a5f4b..2b0d51f 100644 --- a/folkugat_web/dal/sql/playlists/conversion.py +++ b/folkugat_web/dal/sql/playlists/conversion.py @@ -2,7 +2,7 @@ from typing import TypedDict from folkugat_web.model import playlists as model -PlaylistRowTuple = tuple[int, str | None] +PlaylistRowTuple = tuple[int, str | None, int] PlaylistEntryRowTuple = tuple[int, int, int, int | None] @@ -29,3 +29,12 @@ def row_to_playlist_entry(row: PlaylistEntryRowTuple) -> model.PlaylistEntry: set_id=row[2], tema_id=row[3], ) + + +def row_to_playlist(row: PlaylistRowTuple) -> model.Playlist: + return model.Playlist( + id=row[0], + name=row[1], + sets=[], # Empty for list view + hidden=bool(row[2]), + ) diff --git a/folkugat_web/dal/sql/playlists/ddl.py b/folkugat_web/dal/sql/playlists/ddl.py index 2eff45a..116a2ef 100644 --- a/folkugat_web/dal/sql/playlists/ddl.py +++ b/folkugat_web/dal/sql/playlists/ddl.py @@ -11,8 +11,9 @@ def create_playlists_table(con: Connection): query = """ CREATE TABLE IF NOT EXISTS playlists ( id INTEGER PRIMARY KEY, - name TEXT - ) + name TEXT, + hidden INTEGER NOT NULL DEFAULT 1 + ) """ cur = con.cursor() _ = cur.execute(query) diff --git a/folkugat_web/dal/sql/playlists/query.py b/folkugat_web/dal/sql/playlists/query.py index 3d1aaa9..2b2ab0b 100644 --- a/folkugat_web/dal/sql/playlists/query.py +++ b/folkugat_web/dal/sql/playlists/query.py @@ -69,3 +69,35 @@ def get_playlist_name(playlist_id: int, con: Connection | None = None) -> str | _ = cur.execute(query, data) row = cur.fetchone() return row[0] if row else None + + +def get_all_playlists(logged_in: bool = False, con: Connection | None = None) -> Iterator[model.Playlist]: + if logged_in: + # Show all playlists for logged in users + query = """ + SELECT id, name, hidden + FROM playlists + ORDER BY id ASC + """ + else: + # Show only visible playlists for non-logged in users + query = """ + SELECT id, name, hidden + FROM playlists + WHERE hidden = 0 + ORDER BY id ASC + """ + + with get_connection(con) as con: + cur = con.cursor() + _ = cur.execute(query) + rows = cur.fetchall() + + for row in rows: + # Convert to Playlist model without sets for list view + yield model.Playlist( + id=row[0], + name=row[1], + sets=[], # Empty sets list for now + hidden=bool(row[2]) + ) diff --git a/folkugat_web/dal/sql/playlists/write.py b/folkugat_web/dal/sql/playlists/write.py index 8543dfb..a7c7959 100644 --- a/folkugat_web/dal/sql/playlists/write.py +++ b/folkugat_web/dal/sql/playlists/write.py @@ -120,3 +120,20 @@ def update_playlist_name( cur = con.cursor() _ = cur.execute(query, data) return + + +def update_playlist_visibility( + playlist_id: int, + hidden: bool, + con: Connection | None = None, +): + query = """ + UPDATE playlists SET + hidden = :hidden + WHERE id = :id + """ + data = dict(id=playlist_id, hidden=1 if hidden else 0) + with get_connection(con) as con: + cur = con.cursor() + _ = cur.execute(query, data) + return diff --git a/folkugat_web/fragments/__init__.py b/folkugat_web/fragments/__init__.py index e69de29..7d90175 100644 --- a/folkugat_web/fragments/__init__.py +++ b/folkugat_web/fragments/__init__.py @@ -0,0 +1 @@ +from folkugat_web.fragments import llistes \ No newline at end of file diff --git a/folkugat_web/fragments/llistes.py b/folkugat_web/fragments/llistes.py new file mode 100644 index 0000000..f0cae6a --- /dev/null +++ b/folkugat_web/fragments/llistes.py @@ -0,0 +1,17 @@ +from folkugat_web.model.pagines import Pages +from folkugat_web.services import playlists as playlists_service +from folkugat_web.templates import templates + + +def llistes_pagina(request, logged_in): + playlists = playlists_service.get_all_playlists(logged_in=logged_in) + return templates.TemplateResponse( + "fragments/llistes/pagina.html", + { + "request": request, + "logged_in": logged_in, + "playlists": playlists, + "Pages": Pages, + "menu_selected_id": Pages.Llistes, + } + ) diff --git a/folkugat_web/fragments/playlist.py b/folkugat_web/fragments/playlist.py index 5d7ab27..4c36f0a 100644 --- a/folkugat_web/fragments/playlist.py +++ b/folkugat_web/fragments/playlist.py @@ -16,7 +16,7 @@ def add_set( ): new_set = playlists_service.add_set(playlist_id=playlist_id) return templates.TemplateResponse( - "fragments/playlist/set_entry.html", + "fragments/llista/set_entry.html", { "request": request, "logged_in": logged_in, @@ -32,7 +32,7 @@ def get_set(request: Request, playlist_id: int, set_id: int, logged_in: bool): set_entry = playlists_service.get_set(playlist_id=playlist_id, set_id=set_id) if set_entry: return templates.TemplateResponse( - "fragments/playlist/set_entry.html", + "fragments/llista/set_entry.html", { "request": request, "logged_in": logged_in, @@ -55,7 +55,7 @@ def add_tema(request: Request, playlist_id: int, set_id: int, logged_in: bool): new_tema = playlists_service.add_tema(playlist_id=playlist_id, set_id=set_id) new_tema = playlists_service.add_tema_to_tema_in_set(new_tema) return templates.TemplateResponse( - "fragments/playlist/tema_editor.html", + "fragments/llista/tema_editor.html", { "request": request, "logged_in": logged_in, @@ -70,7 +70,7 @@ def get_tema(request: Request, playlist_id: int, set_id: int, entry_id: int, log tema_entry = playlists_service.get_tema(entry_id=entry_id) tema_entry = playlists_service.add_tema_to_tema_in_set(tema_entry) return templates.TemplateResponse( - "fragments/playlist/tema_entry.html", + "fragments/llista/tema_entry.html", { "request": request, "logged_in": logged_in, @@ -85,7 +85,7 @@ def get_tema_editor(request: Request, playlist_id: int, set_id: int, entry_id: i tema_entry = playlists_service.get_tema(entry_id=entry_id) tema_entry = playlists_service.add_tema_to_tema_in_set(tema_entry) return templates.TemplateResponse( - "fragments/playlist/tema_editor.html", + "fragments/llista/tema_editor.html", { "request": request, "logged_in": logged_in, @@ -146,7 +146,7 @@ def busca_tema( offset=0, ) return templates.TemplateResponse( - "fragments/playlist/tema_results.html", + "fragments/llista/tema_results.html", { "request": request, "playlist_id": playlist_id, @@ -163,7 +163,7 @@ def set_tema(request: Request, logged_in: bool, playlist_id: int, set_id: int, e tema_entry = playlists_service.get_tema(entry_id=entry_id) tema_entry = playlists_service.add_tema_to_tema_in_set(tema_entry) return templates.TemplateResponse( - "fragments/playlist/tema_entry.html", + "fragments/llista/tema_entry.html", { "request": request, "logged_in": logged_in, @@ -182,7 +182,7 @@ async def pagina(request: Request, playlist_id: int, logged_in: bool): playlist = playlists_service.add_temes_to_playlist(playlist) playlist = await playlists_service.add_playlist_score_to_playlist(playlist) return templates.TemplateResponse( - "fragments/playlist/pagina.html", + "fragments/llista/pagina.html", { "request": request, "logged_in": logged_in, @@ -200,7 +200,7 @@ def name(request: Request, playlist_id: int, logged_in: bool): from fastapi import HTTPException raise HTTPException(status_code=404, detail="Could not find playlist") return templates.TemplateResponse( - "fragments/playlist/name.html", + "fragments/llista/name.html", { "request": request, "logged_in": logged_in, @@ -216,7 +216,7 @@ def name_editor(request: Request, playlist_id: int, logged_in: bool): from fastapi import HTTPException raise HTTPException(status_code=404, detail="Could not find playlist") return templates.TemplateResponse( - "fragments/playlist/editor/name.html", + "fragments/llista/editor/name.html", { "request": request, "logged_in": logged_in, @@ -224,3 +224,14 @@ def name_editor(request: Request, playlist_id: int, logged_in: bool): "playlist": playlist, } ) + + +def visibility(request: Request, logged_in: bool, playlist): + return templates.TemplateResponse( + "fragments/llista/visibility.html", + { + "request": request, + "logged_in": logged_in, + "playlist": playlist, + } + ) diff --git a/folkugat_web/fragments/set_page.py b/folkugat_web/fragments/set_page.py index ad570eb..8da1c5d 100644 --- a/folkugat_web/fragments/set_page.py +++ b/folkugat_web/fragments/set_page.py @@ -13,7 +13,7 @@ async def pagina(request: Request, playlist_id: int, set_id: int, logged_in: boo set_ = playlists_service.add_temes_to_set(set_) set_ = await playlists_service.add_set_score_to_set(set_) return templates.TemplateResponse( - "fragments/playlist/set/pagina.html", + "fragments/llista/set/pagina.html", { "request": request, "logged_in": logged_in, @@ -36,7 +36,7 @@ async def live(request: Request, logged_in: bool): set_ = playlists_service.add_temes_to_set(playlist.sets[-1]) set_ = await playlists_service.add_set_score_to_set(set_) return templates.TemplateResponse( - "fragments/playlist/set/pagina.html", + "fragments/llista/set/pagina.html", { "request": request, "logged_in": logged_in, @@ -59,7 +59,7 @@ async def live_set(request: Request, logged_in: bool): set_ = playlists_service.add_temes_to_set(playlist.sets[-1]) set_ = await playlists_service.add_set_score_to_set(set_) return templates.TemplateResponse( - "fragments/playlist/set/set_page.html", + "fragments/llista/set/set_page.html", { "request": request, "logged_in": logged_in, diff --git a/folkugat_web/model/pagines.py b/folkugat_web/model/pagines.py index dc193be..3a7f3ca 100644 --- a/folkugat_web/model/pagines.py +++ b/folkugat_web/model/pagines.py @@ -4,3 +4,4 @@ import enum class Pages(enum.IntEnum): Sessions = 0 Temes = 1 + Llistes = 2 diff --git a/folkugat_web/model/playlists.py b/folkugat_web/model/playlists.py index 5d5a6dc..a87df2a 100644 --- a/folkugat_web/model/playlists.py +++ b/folkugat_web/model/playlists.py @@ -87,6 +87,7 @@ class Playlist: id: int name: str | None sets: list[Set] + hidden: bool = True playlist_score: PlaylistScore | None = None def to_playlist_entries(self) -> Iterator[PlaylistEntry]: diff --git a/folkugat_web/services/playlists.py b/folkugat_web/services/playlists.py index 97a5db4..2609d36 100644 --- a/folkugat_web/services/playlists.py +++ b/folkugat_web/services/playlists.py @@ -216,3 +216,20 @@ async def add_playlist_score_to_playlist(playlist: playlists.Playlist) -> playli ) else: return playlist + + +def get_all_playlists(logged_in: bool = False) -> list[playlists.Playlist]: + return list(query.get_all_playlists(logged_in=logged_in)) + + +def set_visibility(playlist_id: int, hidden: bool) -> playlists.Playlist: + with get_connection() as con: + playlist = get_playlist(playlist_id=playlist_id, con=con) + if playlist is None: + raise ValueError(f"No playlist found with playlist_id = {playlist_id}!") + + # Update hidden status in database + write.update_playlist_visibility(playlist_id=playlist_id, hidden=hidden, con=con) + + # Return updated playlist + return dataclasses.replace(playlist, hidden=hidden) diff --git a/scripts/07_add_playlist_hidden.py b/scripts/07_add_playlist_hidden.py new file mode 100644 index 0000000..ad827d0 --- /dev/null +++ b/scripts/07_add_playlist_hidden.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +""" +Migration script to add hidden column to playlists table and set all existing playlists to hidden. +""" + +import sqlite3 +import sys +from pathlib import Path + +# Add the project root to the path so we can import project modules +project_root = Path(__file__).parent +sys.path.insert(0, str(project_root)) + +from folkugat_web.config.db import DB_FILE + + +def main(): + print(f"Connecting to database at: {DB_FILE}") + + with sqlite3.connect(DB_FILE) as con: + cur = con.cursor() + + # Check if hidden column already exists + cur.execute("PRAGMA table_info(playlists)") + columns = [column[1] for column in cur.fetchall()] + + if 'hidden' not in columns: + print("Adding hidden column to playlists table...") + cur.execute("ALTER TABLE playlists ADD COLUMN hidden INTEGER NOT NULL DEFAULT 1") + print("Column added successfully.") + else: + print("Hidden column already exists.") + + # Set all existing playlists to hidden (1) + print("Setting all existing playlists to hidden...") + cur.execute("UPDATE playlists SET hidden = 1") + updated_count = cur.rowcount + print(f"Updated {updated_count} playlists to hidden.") + + con.commit() + + print("Migration completed successfully!") + + +if __name__ == "__main__": + main() \ No newline at end of file