Desacoblar playlists de sessions i afegir slow jams
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
lilypond-with-fonts
|
||||
# Project tools
|
||||
sqlite
|
||||
lazysql
|
||||
opencode
|
||||
];
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
from folkugat_web.api.router import get_router
|
||||
|
||||
from . import auth, index, sessio, sessions, tema, temes
|
||||
from . import auth, index, playlist, sessio, sessions, tema, temes
|
||||
|
||||
router = get_router()
|
||||
|
||||
router.include_router(auth.router)
|
||||
router.include_router(index.router)
|
||||
router.include_router(playlist.router)
|
||||
router.include_router(sessio.router)
|
||||
router.include_router(sessions.router)
|
||||
router.include_router(tema.router)
|
||||
router.include_router(temes.router)
|
||||
router.include_router(auth.router)
|
||||
router.include_router(index.router)
|
||||
|
||||
__all__ = ["router"]
|
||||
|
||||
9
folkugat_web/api/routes/playlist/__init__.py
Normal file
9
folkugat_web/api/routes/playlist/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from folkugat_web.api.router import get_router
|
||||
|
||||
from . import playlist, set_page
|
||||
|
||||
router = get_router()
|
||||
router.include_router(set_page.router)
|
||||
router.include_router(playlist.router)
|
||||
|
||||
__all__ = ["router"]
|
||||
@@ -2,141 +2,139 @@ from typing import Annotated
|
||||
|
||||
from fastapi import Form, Request
|
||||
from folkugat_web.api.router import get_router
|
||||
from folkugat_web.fragments import live
|
||||
from folkugat_web.fragments.sessio import playlist
|
||||
from folkugat_web.fragments import playlist
|
||||
from folkugat_web.services import auth
|
||||
from folkugat_web.services.temes import write as temes_service
|
||||
from folkugat_web.templates import templates
|
||||
|
||||
router = get_router()
|
||||
|
||||
|
||||
@router.post("/api/sessio/{session_id}/playlist/set")
|
||||
@router.post("/api/playlist/{playlist_id}/set")
|
||||
def add_set(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
):
|
||||
return playlist.add_set(
|
||||
request=request,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
logged_in=logged_in,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/sessio/{session_id}/playlist/set/{set_id}")
|
||||
@router.get("/api/playlist/{playlist_id}/set/{set_id}")
|
||||
def get_set(
|
||||
request: Request,
|
||||
logged_in: auth.LoggedIn,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
):
|
||||
return playlist.get_set(
|
||||
request=request,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
logged_in=logged_in,
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/api/sessio/{session_id}/playlist/set/{set_id}")
|
||||
@router.delete("/api/playlist/{playlist_id}/set/{set_id}")
|
||||
def delete_set(
|
||||
_: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
):
|
||||
return playlist.delete_set(
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/sessio/{session_id}/playlist/set/{set_id}")
|
||||
@router.post("/api/playlist/{playlist_id}/set/{set_id}")
|
||||
def add_tema(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
):
|
||||
return playlist.add_tema(
|
||||
request=request,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
logged_in=logged_in,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}")
|
||||
@router.get("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}")
|
||||
def get_tema(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
):
|
||||
return playlist.get_tema(
|
||||
request=request,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
logged_in=logged_in,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}/editor")
|
||||
@router.get("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}/editor")
|
||||
def get_tema_editor(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
):
|
||||
return playlist.get_tema_editor(
|
||||
request=request,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
logged_in=logged_in,
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}")
|
||||
@router.delete("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}")
|
||||
def delete_tema(
|
||||
_: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
):
|
||||
return playlist.delete_tema(
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}/busca")
|
||||
@router.get("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}/busca")
|
||||
def busca_tema(
|
||||
request: Request,
|
||||
_: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
query: str,
|
||||
):
|
||||
return playlist.busca_tema(
|
||||
request=request,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
query=query,
|
||||
)
|
||||
|
||||
|
||||
@router.put("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}")
|
||||
@router.put("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}")
|
||||
def set_tema(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
tema_id: Annotated[int, Form()],
|
||||
@@ -144,36 +142,36 @@ def set_tema(
|
||||
return playlist.set_tema(
|
||||
request=request,
|
||||
logged_in=logged_in,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
tema_id=tema_id,
|
||||
)
|
||||
|
||||
|
||||
@router.put("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}/unknown")
|
||||
@router.put("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}/unknown")
|
||||
def set_tema_unknown(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
):
|
||||
return playlist.set_tema(
|
||||
request=request,
|
||||
logged_in=logged_in,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
tema_id=None,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/sessio/{session_id}/playlist/set/{set_id}/tema/{entry_id}")
|
||||
@router.post("/api/playlist/{playlist_id}/set/{set_id}/tema/{entry_id}")
|
||||
def set_tema_new(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
title: Annotated[str, Form()],
|
||||
@@ -182,7 +180,7 @@ def set_tema_new(
|
||||
return playlist.set_tema(
|
||||
request=request,
|
||||
logged_in=logged_in,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
entry_id=entry_id,
|
||||
tema_id=new_tema.id,
|
||||
@@ -7,11 +7,11 @@ from folkugat_web.templates import templates
|
||||
router = get_router()
|
||||
|
||||
|
||||
@router.get("/sessio/{session_id}/set/{set_id}")
|
||||
@router.get("/playlist/{playlist_id}/set/{set_id}")
|
||||
def page(
|
||||
request: Request,
|
||||
logged_in: auth.LoggedIn,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
):
|
||||
return templates.TemplateResponse(
|
||||
@@ -19,17 +19,22 @@ def page(
|
||||
{
|
||||
"request": request,
|
||||
"page_title": "Folkugat",
|
||||
"content": f"/api/content/sessio/{session_id}/set/{set_id}",
|
||||
"content": f"/api/content/playlist/{playlist_id}/set/{set_id}",
|
||||
"logged_in": logged_in,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/content/sessio/{session_id}/set/{set_id}")
|
||||
@router.get("/api/content/playlist/{playlist_id}/set/{set_id}")
|
||||
async def contingut(
|
||||
request: Request,
|
||||
logged_in: auth.LoggedIn,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
):
|
||||
return await set_page.pagina(request, session_id, set_id, logged_in)
|
||||
return await set_page.pagina(
|
||||
request=request,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
logged_in=logged_in,
|
||||
)
|
||||
@@ -1,12 +1,11 @@
|
||||
from folkugat_web.api.router import get_router
|
||||
|
||||
from . import cartell, index, live, playlist, set_page
|
||||
from . import cartell, index, live, notes
|
||||
|
||||
router = get_router()
|
||||
router.include_router(cartell.router)
|
||||
router.include_router(index.router)
|
||||
router.include_router(live.router)
|
||||
router.include_router(set_page.router)
|
||||
router.include_router(playlist.router)
|
||||
router.include_router(notes.router)
|
||||
|
||||
__all__ = ["router"]
|
||||
|
||||
47
folkugat_web/api/routes/sessio/notes.py
Normal file
47
folkugat_web/api/routes/sessio/notes.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import dataclasses
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import HTTPException, Request
|
||||
from fastapi.params import Form
|
||||
from folkugat_web.api.router import get_router
|
||||
from folkugat_web.fragments.sessio import notes
|
||||
from folkugat_web.services import auth
|
||||
from folkugat_web.services import sessions as sessions_service
|
||||
|
||||
router = get_router()
|
||||
|
||||
|
||||
@router.get("/api/sessio/{session_id}/notes")
|
||||
def get_notes(
|
||||
request: Request,
|
||||
logged_in: auth.LoggedIn,
|
||||
session_id: int,
|
||||
):
|
||||
return notes.notes(request, session_id, logged_in)
|
||||
|
||||
|
||||
@router.get("/api/sessio/{session_id}/notes/editor")
|
||||
def get_notes_editor(
|
||||
request: Request,
|
||||
_: auth.RequireLogin,
|
||||
session_id: int,
|
||||
):
|
||||
return notes.notes_editor(request, session_id)
|
||||
|
||||
|
||||
@router.put("/api/sessio/{session_id}/notes")
|
||||
async def set_notes(
|
||||
request: Request,
|
||||
logged_in: auth.RequireLogin,
|
||||
session_id: int,
|
||||
content: Annotated[str, Form()],
|
||||
):
|
||||
session = sessions_service.get_session(session_id=session_id)
|
||||
if not session:
|
||||
raise HTTPException(status_code=404, detail="Could not find session")
|
||||
new_session = dataclasses.replace(
|
||||
session,
|
||||
notes=content.strip(),
|
||||
)
|
||||
sessions_service.set_session(new_session)
|
||||
return notes.notes(request, session_id, logged_in)
|
||||
File diff suppressed because one or more lines are too long
@@ -1,14 +1,14 @@
|
||||
<ul id="playlist-{{ session.id }}" class="">
|
||||
<ul id="playlist-{{ playlist_id }}" class="">
|
||||
{% for set_entry in playlist.sets %}
|
||||
{% set set_id = set_entry.id %}
|
||||
{% include "fragments/sessio/set_entry.html" %}
|
||||
{% include "fragments/playlist/set_entry.html" %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if logged_in %}
|
||||
<div class="flex flex-col items-center">
|
||||
<button class="text-beige mt-2"
|
||||
hx-post="/api/sessio/{{ session.id }}/playlist/set"
|
||||
hx-target="#playlist-{{ session.id }}"
|
||||
hx-post="/api/playlist/{{ playlist_id }}/set"
|
||||
hx-target="#playlist-{{ playlist_id }}"
|
||||
hx-swap="beforeend transition:true">
|
||||
<i class="fa fa-plus" aria-hidden="true"></i>
|
||||
Afegeix set
|
||||
@@ -0,0 +1,2 @@
|
||||
{% include "fragments/menu.html" %}
|
||||
{% include "fragments/playlist/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/sessio/set/tema_title.html" %}
|
||||
{% include "fragments/playlist/set/tema_title.html" %}
|
||||
{% else %}
|
||||
<h3 class="text-center text-3xl p-4"> <i>Desconegut</i> </h3>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<div class="mx-12">
|
||||
<hr class="h-px mt-1 mb-3 bg-beige border-0">
|
||||
{% include "fragments/sessio/set/set_score.html"%}
|
||||
{% include "fragments/playlist/set/set_score.html"%}
|
||||
</div>
|
||||
{% 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/sessio/set/tema.html"%}
|
||||
{% include "fragments/playlist/set/tema.html"%}
|
||||
{% else %}
|
||||
<h3 class="text-center text-3xl p-4">
|
||||
<i>Desconegut</i>
|
||||
@@ -1,4 +1,4 @@
|
||||
{% include "fragments/sessio/set/tema_title.html" %}
|
||||
{% include "fragments/playlist/set/tema_title.html" %}
|
||||
<div class="mx-12 text-left">
|
||||
|
||||
{% if tema.main_score() is not none %}
|
||||
@@ -2,12 +2,12 @@
|
||||
m-4 rounded-lg bg-white
|
||||
px-2 py-1 my-1"
|
||||
id="set-entry-{{ set_id }}"
|
||||
hx-get="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}"
|
||||
hx-get="/api/playlist/{{ playlist_id }}/set/{{ set_id }}"
|
||||
hx-target="#set-entry-{{ set_id }}"
|
||||
hx-swap="outerHTML"
|
||||
hx-trigger="reload-set-{{ set_id }}">
|
||||
{% if set_entry.temes | length > 1 or not set_entry.temes[0].tema %}
|
||||
{% set set_url = "/sessio/%d/set/%d" | format(session_id, set_id) %}
|
||||
{% set set_url = "/playlist/%d/set/%d" | format(playlist_id, set_id) %}
|
||||
{% else %}
|
||||
{% set set_url = "/tema/%d" | format(set_entry.temes[0].tema_id) %}
|
||||
{% endif %}
|
||||
@@ -25,7 +25,7 @@
|
||||
w-full max-w-[655px]">
|
||||
{% if logged_in %}
|
||||
<button class="text-beige w-full"
|
||||
hx-delete="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}"
|
||||
hx-delete="/api/playlist/{{ playlist_id }}/set/{{ set_id }}"
|
||||
hx-target="#set-entry-{{ set_id }}"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-times" aria-hidden="true"></i>
|
||||
@@ -36,15 +36,15 @@
|
||||
class="flex flex-col items-start w-full">
|
||||
{% for tema_entry in set_entry.temes %}
|
||||
{% if new_entry %}
|
||||
{% include "fragments/sessio/tema_editor.html" %}
|
||||
{% include "fragments/playlist/tema_editor.html" %}
|
||||
{% else %}
|
||||
{% include "fragments/sessio/tema_entry.html" %}
|
||||
{% include "fragments/playlist/tema_entry.html" %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ol>
|
||||
{% if logged_in %}
|
||||
<button class="text-beige mt-2 w-full"
|
||||
hx-post="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}"
|
||||
hx-post="/api/playlist/{{ playlist_id }}/set/{{ set_id }}"
|
||||
hx-target="#set-entry-{{ set_id }}-list"
|
||||
hx-swap="beforeend transition:true">
|
||||
<i class="fa fa-plus" aria-hidden="true"></i>
|
||||
@@ -12,13 +12,13 @@
|
||||
class="border border-beige focus:outline-none
|
||||
rounded text-center text-black
|
||||
p-1 m-1"
|
||||
hx-get="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ tema_entry.id }}/busca"
|
||||
hx-get="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ tema_entry.id }}/busca"
|
||||
hx-trigger="revealed, keyup delay:500ms changed"
|
||||
hx-target="#tune-entry-{{ tema_entry.id }}-search-results"
|
||||
hx-swap="outerHTML"/>
|
||||
<button title="Descarta els canvis"
|
||||
class="text-beige mx-1"
|
||||
hx-get="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ tema_entry.id }}"
|
||||
hx-get="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ tema_entry.id }}"
|
||||
hx-target="#tune-entry-{{ tema_entry.id }}"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-times" aria-hidden="true"></i>
|
||||
@@ -15,14 +15,14 @@
|
||||
<div class="flex-none flex flex-row shrink-0">
|
||||
<button title="Edita el tema"
|
||||
class="text-beige mx-1"
|
||||
hx-get="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ tema_entry.id }}/editor"
|
||||
hx-get="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ tema_entry.id }}/editor"
|
||||
hx-target="#tune-entry-{{ tema_entry.id }}"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button title="Esborra el tema"
|
||||
class="text-beige mx-1"
|
||||
hx-delete="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ tema_entry.id }}"
|
||||
hx-delete="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ tema_entry.id }}"
|
||||
hx-target="#tune-entry-{{ tema_entry.id }}"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-times" aria-hidden="true"></i>
|
||||
@@ -4,7 +4,7 @@
|
||||
<li>
|
||||
<button class="bg-beige text-brown rounded
|
||||
m-1 px-2"
|
||||
hx-put="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ entry_id }}"
|
||||
hx-put="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ entry_id }}"
|
||||
hx-vals='{"tema_id": "{{ tema.id }}"}'
|
||||
hx-target="#tune-entry-{{ entry_id }}"
|
||||
hx-swap="outerHTML">
|
||||
@@ -15,7 +15,7 @@
|
||||
<li>
|
||||
<button class="border border-beige text-beige rounded
|
||||
m-1 px-2"
|
||||
hx-put="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ entry_id }}/unknown"
|
||||
hx-put="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ entry_id }}/unknown"
|
||||
hx-target="#tune-entry-{{ entry_id }}"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-question" aria-hidden="true"></i>
|
||||
@@ -25,7 +25,7 @@
|
||||
<li>
|
||||
<button class="border border-beige text-beige rounded
|
||||
m-1 px-2"
|
||||
hx-post="/api/sessio/{{ session_id }}/playlist/set/{{ set_id }}/tema/{{ entry_id }}"
|
||||
hx-post="/api/playlist/{{ playlist_id }}/set/{{ set_id }}/tema/{{ entry_id }}"
|
||||
hx-vals='{"title": "{{ query }}"}'
|
||||
hx-target="#tune-entry-{{ entry_id }}"
|
||||
hx-swap="outerHTML">
|
||||
13
folkugat_web/assets/templates/fragments/sessio/notes.html
Normal file
13
folkugat_web/assets/templates/fragments/sessio/notes.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<h4 class="py-4 text-xl text-beige">
|
||||
Notes
|
||||
{% if logged_in %}
|
||||
<button title="Edita les notes"
|
||||
class="mx-1"
|
||||
hx-get="/api/sessio/{{ session_id }}/notes/editor"
|
||||
hx-target="#notes"
|
||||
hx-swap="innerHTML">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
</h4>
|
||||
{{ notes | safe }}
|
||||
@@ -0,0 +1,28 @@
|
||||
<h4 class="py-4 text-xl text-beige">Notes</h4>
|
||||
<form id="notes-form"
|
||||
class="w-full">
|
||||
<h5 class="text-sm text-beige text-right">
|
||||
<button title="Desa els canvis"
|
||||
class="mx-1"
|
||||
hx-put="/api/sessio/{{session_id}}/notes"
|
||||
hx-target="#notes"
|
||||
hx-swap="innerHTML">
|
||||
<i class="fa fa-check" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button title="Descarta els canvis"
|
||||
class="mx-1"
|
||||
hx-get="/api/sessio/{{session_id}}/notes"
|
||||
hx-target="#notes"
|
||||
hx-swap="innerHTML">
|
||||
<i class="fa fa-times" aria-hidden="true"></i>
|
||||
</button>
|
||||
</h5>
|
||||
<hr class="h-px mt-1 mb-3 bg-beige border-0">
|
||||
<textarea name="content"
|
||||
placeholder="Notes"
|
||||
rows="{{ max(notes.count('\n') + 1, 5) }}"
|
||||
class="border border-beige focus:outline-none
|
||||
w-full text-left
|
||||
rounded
|
||||
bg-brown p-2 m-0">{{notes}}</textarea>
|
||||
</form>
|
||||
@@ -31,20 +31,26 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if logged_in or session.notes %}
|
||||
<div class="text-left">
|
||||
<h4 class="py-4 text-xl text-beige">Notes</h4>
|
||||
{% if session.notes %}{{ session.notes }}{% endif %}
|
||||
<div id="notes"
|
||||
class="text-left">
|
||||
{% set notes = session.notes if session.notes else "" %}
|
||||
{% include "fragments/sessio/notes.html" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if logged_in or False %}
|
||||
{% if logged_in or (session.slowjam and session.slowjam.sets) %}
|
||||
<div class="text-left">
|
||||
<h4 class="py-4 text-xl text-beige">Slow Jam</h4>
|
||||
<h4 class="py-4 text-xl text-beige mt-2">Slow Jam</h4>
|
||||
{% set playlist_id = session.slowjam.id %}
|
||||
{% set playlist = session.slowjam %}
|
||||
{% include "fragments/playlist/playlist.html" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if logged_in or playlist.sets %}
|
||||
{% if logged_in or (session.setlist and session.setlist.sets) %}
|
||||
<div class="text-left">
|
||||
<h4 class="py-4 text-xl text-beige mt-2">Temes tocats</h4>
|
||||
{% include "fragments/sessio/playlist.html" %}
|
||||
{% set playlist_id = session.setlist.id %}
|
||||
{% set playlist = session.setlist %}
|
||||
{% include "fragments/playlist/playlist.html" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
{% include "fragments/menu.html" %}
|
||||
{% include "fragments/sessio/set/set_page.html" %}
|
||||
@@ -2,12 +2,13 @@ from typing import TypedDict
|
||||
|
||||
from folkugat_web.model import playlists as model
|
||||
|
||||
PlaylistRowTuple = tuple[int, int, int, int | None]
|
||||
PlaylistRowTuple = tuple[int, str | None]
|
||||
PlaylistEntryRowTuple = tuple[int, int, int, int | None]
|
||||
|
||||
|
||||
class PlaylistRowDict(TypedDict):
|
||||
id: int | None
|
||||
session_id: int
|
||||
playlist_id: int
|
||||
set_id: int
|
||||
tema_id: int | None
|
||||
|
||||
@@ -15,16 +16,16 @@ class PlaylistRowDict(TypedDict):
|
||||
def playlist_entry_to_row(tema_in_set: model.PlaylistEntry) -> PlaylistRowDict:
|
||||
return {
|
||||
'id': tema_in_set.id,
|
||||
'session_id': tema_in_set.session_id,
|
||||
'playlist_id': tema_in_set.playlist_id,
|
||||
'set_id': tema_in_set.set_id,
|
||||
'tema_id': tema_in_set.tema_id,
|
||||
}
|
||||
|
||||
|
||||
def row_to_playlist_entry(row: PlaylistRowTuple) -> model.PlaylistEntry:
|
||||
def row_to_playlist_entry(row: PlaylistEntryRowTuple) -> model.PlaylistEntry:
|
||||
return model.PlaylistEntry(
|
||||
id=row[0],
|
||||
session_id=row[1],
|
||||
playlist_id=row[1],
|
||||
set_id=row[2],
|
||||
tema_id=row[3],
|
||||
)
|
||||
|
||||
@@ -4,15 +4,29 @@ from folkugat_web.dal.sql import Connection, get_connection
|
||||
def create_db(con: Connection | None = None):
|
||||
with get_connection(con) as con:
|
||||
create_playlists_table(con)
|
||||
create_playlist_entries_table(con)
|
||||
|
||||
|
||||
def create_playlists_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS playlists (
|
||||
id INTEGER PRIMARY KEY,
|
||||
session_id INTEGER NOT NULL,
|
||||
set_id INTEGER NOT NULL,
|
||||
tema_id INTEGER
|
||||
name TEXT
|
||||
)
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_playlist_entries_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS playlist_entries (
|
||||
id INTEGER PRIMARY KEY,
|
||||
playlist_id INTEGER NOT NULL,
|
||||
set_id INTEGER NOT NULL,
|
||||
tema_id INTEGER,
|
||||
FOREIGN KEY (playlist_id) REFERENCES playlists(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (tema_id) REFERENCES temes(id) ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
cur = con.cursor()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from collections.abc import Iterable, Iterator
|
||||
from collections.abc import Iterator
|
||||
from typing import TypedDict
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.dal.sql.sessions import conversion as sessions_conversion
|
||||
from folkugat_web.dal.sql.temes.conversion import row_to_tema
|
||||
from folkugat_web.model import playlists as model
|
||||
from folkugat_web.model import temes as temes_model
|
||||
from folkugat_web.model.sessions import Session
|
||||
from folkugat_web.utils import groupby
|
||||
|
||||
@@ -15,13 +13,13 @@ from . import conversion
|
||||
class QueryData(TypedDict, total=False):
|
||||
id: int
|
||||
set_id: int
|
||||
session_id: int
|
||||
playlist_id: int
|
||||
|
||||
|
||||
def _filter_clause(
|
||||
entry_id: int | None = None,
|
||||
set_id: int | None = None,
|
||||
session_id: int | None = None,
|
||||
playlist_id: int | None = None,
|
||||
) -> tuple[str, QueryData]:
|
||||
filter_clauses: list[str] = []
|
||||
query_data: QueryData = {}
|
||||
@@ -32,9 +30,9 @@ def _filter_clause(
|
||||
if set_id is not None:
|
||||
filter_clauses.append("set_id = :set_id")
|
||||
query_data["set_id"] = set_id
|
||||
if session_id is not None:
|
||||
filter_clauses.append("session_id = :session_id")
|
||||
query_data["session_id"] = session_id
|
||||
if playlist_id is not None:
|
||||
filter_clauses.append("playlist_id = :playlist_id")
|
||||
query_data["playlist_id"] = playlist_id
|
||||
|
||||
return " AND ".join(filter_clauses), query_data
|
||||
|
||||
@@ -42,14 +40,14 @@ def _filter_clause(
|
||||
def get_playlist_entries(
|
||||
entry_id: int | None = None,
|
||||
set_id: int | None = None,
|
||||
session_id: int | None = None,
|
||||
playlist_id: int | None = None,
|
||||
con: Connection | None = None,
|
||||
) -> Iterator[model.PlaylistEntry]:
|
||||
filter_clause, data = _filter_clause(entry_id=entry_id, set_id=set_id, session_id=session_id)
|
||||
filter_clause, data = _filter_clause(entry_id=entry_id, set_id=set_id, playlist_id=playlist_id)
|
||||
query = f"""
|
||||
SELECT
|
||||
id, session_id, set_id, tema_id
|
||||
FROM playlists
|
||||
id, playlist_id, set_id, tema_id
|
||||
FROM playlist_entries
|
||||
WHERE {filter_clause}
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
@@ -57,59 +55,3 @@ def get_playlist_entries(
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
return map(conversion.row_to_playlist_entry, cur.fetchall())
|
||||
|
||||
|
||||
GetTuneSessionsRow = tuple[int, int, str, str, str, str | None, str | None, str | None, str | None, bool]
|
||||
|
||||
|
||||
def get_tune_sessions(tema_ids: list[int], con: Connection | None = None) -> dict[int, list[Session]]:
|
||||
placeholders = ", ".join(["?" for _ in tema_ids])
|
||||
query = f"""
|
||||
SELECT
|
||||
p.tema_id, s.id, s.date, s.start_time, s.end_time, s.venue_name,
|
||||
s.venue_url, s.notes, s.cartell_url, s.is_live
|
||||
FROM playlists p JOIN sessions s ON p.session_id = s.id
|
||||
WHERE p.tema_id IN ({placeholders})
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, tema_ids)
|
||||
result_rows: Iterable[GetTuneSessionsRow] = cur.fetchall()
|
||||
return dict(groupby(
|
||||
result_rows,
|
||||
key_fn=lambda row: row[0],
|
||||
group_fn=lambda rows: list(sessions_conversion.row_to_session(row[1:]) for row in rows)
|
||||
))
|
||||
|
||||
|
||||
CommonlyPlayedTuneRow = tuple[int, str, str, str, str, int, int]
|
||||
|
||||
|
||||
def get_commonly_played_tunes(
|
||||
tema_id: int,
|
||||
con: Connection | None = None,
|
||||
) -> list[temes_model.CommonlyPlayedTema]:
|
||||
query = """
|
||||
SELECT
|
||||
id, title, alternatives, creation_date, modification_date, hidden, count
|
||||
FROM (
|
||||
SELECT tema_id, count(*) count FROM playlists p JOIN (
|
||||
SELECT session_id, set_id
|
||||
FROM playlists
|
||||
WHERE tema_id = ?
|
||||
) s
|
||||
ON p.session_id == s.session_id AND p.set_id == s.set_id
|
||||
WHERE tema_id != ?
|
||||
GROUP BY tema_id
|
||||
) common JOIN temes t ON common.tema_id == t.id
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, [tema_id, tema_id])
|
||||
result_rows: Iterable[CommonlyPlayedTuneRow] = cur.fetchall()
|
||||
return [
|
||||
temes_model.CommonlyPlayedTema(
|
||||
tema=row_to_tema(row[:6]),
|
||||
count=row[6],
|
||||
) for row in result_rows
|
||||
]
|
||||
|
||||
@@ -4,27 +4,66 @@ from folkugat_web.model import playlists as model
|
||||
from . import conversion
|
||||
|
||||
|
||||
def insert_playlist_entry(pl_entry: model.PlaylistEntry, con: Connection | None = None) -> model.PlaylistEntry:
|
||||
def create_playlist(
|
||||
name: str | None = None,
|
||||
con: Connection | None = None,
|
||||
) -> int:
|
||||
query = """
|
||||
INSERT INTO playlists
|
||||
(id, session_id, set_id, tema_id)
|
||||
(name)
|
||||
VALUES
|
||||
(:id, :session_id, :set_id, :tema_id)
|
||||
(:name)
|
||||
RETURNING *
|
||||
"""
|
||||
data = dict(name=name)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
row: conversion.PlaylistRowTuple = cur.fetchone()
|
||||
return row[0]
|
||||
|
||||
|
||||
def delete_playlist(
|
||||
playlist_id: int,
|
||||
con: Connection | None = None,
|
||||
) -> None:
|
||||
query = """
|
||||
DELETE FROM playlists
|
||||
WHERE id = :id
|
||||
"""
|
||||
data = dict(playlist_id=playlist_id)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
|
||||
def insert_playlist_entry(
|
||||
pl_entry: model.PlaylistEntry,
|
||||
con: Connection | None = None,
|
||||
) -> model.PlaylistEntry:
|
||||
query = """
|
||||
INSERT INTO playlist_entries
|
||||
(id, playlist_id, set_id, tema_id)
|
||||
VALUES
|
||||
(:id, :playlist_id, :set_id, :tema_id)
|
||||
RETURNING *
|
||||
"""
|
||||
data = conversion.playlist_entry_to_row(pl_entry)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
row: conversion.PlaylistRowTuple = cur.fetchone()
|
||||
row: conversion.PlaylistEntryRowTuple = cur.fetchone()
|
||||
return conversion.row_to_playlist_entry(row)
|
||||
|
||||
|
||||
def update_playlist_entry(entry: model.PlaylistEntry, con: Connection | None = None):
|
||||
def update_playlist_entry(
|
||||
entry: model.PlaylistEntry,
|
||||
con: Connection | None = None,
|
||||
):
|
||||
query = """
|
||||
UPDATE playlists
|
||||
UPDATE playlist_entries
|
||||
SET
|
||||
id = :id, session_id = :session_id, set_id = :set_id, tema_id = :tema_id
|
||||
id = :id, playlist_id = :playlist_id, set_id = :set_id, tema_id = :tema_id
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
@@ -35,9 +74,12 @@ def update_playlist_entry(entry: model.PlaylistEntry, con: Connection | None = N
|
||||
return
|
||||
|
||||
|
||||
def delete_playlist_entry(entry_id: int, con: Connection | None = None):
|
||||
def delete_playlist_entry(
|
||||
entry_id: int,
|
||||
con: Connection | None = None,
|
||||
):
|
||||
query = """
|
||||
DELETE FROM playlists
|
||||
DELETE FROM playlist_entries
|
||||
WHERE id = :id
|
||||
"""
|
||||
data = dict(id=entry_id)
|
||||
@@ -47,12 +89,16 @@ def delete_playlist_entry(entry_id: int, con: Connection | None = None):
|
||||
return
|
||||
|
||||
|
||||
def delete_playlist_set(session_id: int, set_id: int, con: Connection | None = None):
|
||||
def delete_playlist_set(
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
con: Connection | None = None,
|
||||
):
|
||||
query = """
|
||||
DELETE FROM playlists
|
||||
WHERE session_id = :session_id AND set_id = :set_id
|
||||
DELETE FROM playlist_entries
|
||||
WHERE playlist_id = :playlist_id AND set_id = :set_id
|
||||
"""
|
||||
data = dict(session_id=session_id, set_id=set_id)
|
||||
data = dict(playlist_id=playlist_id, set_id=set_id)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
@@ -4,6 +4,7 @@ from folkugat_web.dal.sql import Connection, get_connection
|
||||
def create_db(con: Connection | None = None):
|
||||
with get_connection(con) as con:
|
||||
create_sessions_table(con)
|
||||
create_session_playlists_table(con)
|
||||
|
||||
|
||||
def create_sessions_table(con: Connection):
|
||||
@@ -22,3 +23,18 @@ def create_sessions_table(con: Connection):
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_session_playlists_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS session_playlists (
|
||||
session_id INTEGER,
|
||||
playlist_type TEXT,
|
||||
playlist_id INTEGER NOT NULL,
|
||||
PRIMARY KEY (session_id, playlist_type),
|
||||
FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (playlist_id) REFERENCES playlists(id) ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
138
folkugat_web/dal/sql/sessions/playlists.py
Normal file
138
folkugat_web/dal/sql/sessions/playlists.py
Normal file
@@ -0,0 +1,138 @@
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.dal.sql.temes.conversion import row_to_tema
|
||||
from folkugat_web.model import sessions as sessions_model
|
||||
from folkugat_web.model import temes as temes_model
|
||||
from folkugat_web.model.playlists import PlaylistType
|
||||
from folkugat_web.utils import groupby
|
||||
|
||||
from . import conversion
|
||||
|
||||
|
||||
def get_playlist_id(
|
||||
session_id: int,
|
||||
playlist_type: PlaylistType,
|
||||
con: Connection | None = None,
|
||||
) -> int | None:
|
||||
query = f"""
|
||||
SELECT playlist_id
|
||||
FROM session_playlists
|
||||
WHERE
|
||||
session_id = :session_id AND
|
||||
playlist_type = :playlist_type
|
||||
"""
|
||||
data = dict(
|
||||
session_id=session_id,
|
||||
playlist_type=playlist_type.value,
|
||||
)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
if row := cur.fetchone():
|
||||
return row[0]
|
||||
return None
|
||||
|
||||
|
||||
def insert_playlist(
|
||||
session_id: int,
|
||||
playlist_type: PlaylistType,
|
||||
playlist_id: int,
|
||||
con: Connection | None = None,
|
||||
):
|
||||
query = f"""
|
||||
INSERT INTO session_playlists
|
||||
(session_id, playlist_type, playlist_id)
|
||||
VALUES
|
||||
(:session_id, :playlist_type, :playlist_id)
|
||||
"""
|
||||
data = dict(
|
||||
session_id=session_id,
|
||||
playlist_type=playlist_type.value,
|
||||
playlist_id=playlist_id,
|
||||
)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
|
||||
def delete_playlist(
|
||||
session_id: int,
|
||||
playlist_type: PlaylistType,
|
||||
con: Connection | None = None,
|
||||
):
|
||||
query = f"""
|
||||
DELETE FROM session_playlists
|
||||
WHERE
|
||||
session_id = :session_id AND
|
||||
playlist_type = :playlist_type
|
||||
"""
|
||||
data = dict(
|
||||
session_id=session_id,
|
||||
playlist_type=playlist_type.value,
|
||||
)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
|
||||
GetTuneSessionsRow = tuple[int, int, str, str, str, str | None, str | None, str | None, str | None, bool]
|
||||
|
||||
|
||||
def get_tune_sessions(
|
||||
tema_ids: list[int],
|
||||
con: Connection | None = None,
|
||||
) -> dict[int, list[sessions_model.Session]]:
|
||||
placeholders = ", ".join(["?" for _ in tema_ids])
|
||||
query = f"""
|
||||
SELECT
|
||||
p.tema_id, s.id, s.date, s.start_time, s.end_time, s.venue_name,
|
||||
s.venue_url, s.notes, s.cartell_url, s.is_live
|
||||
FROM playlist_entries p
|
||||
JOIN session_playlists sp ON p.playlist_id = sp.playlist_id
|
||||
JOIN sessions s ON sp.session_id = s.id
|
||||
WHERE
|
||||
p.tema_id IN ({placeholders}) AND
|
||||
sp.playlist_type = "{PlaylistType.SESSION_SETLIST.value}"
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, tema_ids)
|
||||
result_rows: list[GetTuneSessionsRow] = cur.fetchall()
|
||||
return dict(groupby(
|
||||
result_rows,
|
||||
key_fn=lambda row: row[0],
|
||||
group_fn=lambda rows: list(conversion.row_to_session(row[1:]) for row in rows)
|
||||
))
|
||||
|
||||
|
||||
CommonlyPlayedTuneRow = tuple[int, str, str, str, str, int, int]
|
||||
|
||||
|
||||
def get_commonly_played_tunes(
|
||||
tema_id: int,
|
||||
con: Connection | None = None,
|
||||
) -> list[temes_model.CommonlyPlayedTema]:
|
||||
query = f"""
|
||||
SELECT
|
||||
id, title, alternatives, creation_date, modification_date, hidden, count
|
||||
FROM (
|
||||
SELECT tema_id, count(*) count FROM playlist_entries p JOIN (
|
||||
SELECT pe.playlist_id, pe.set_id
|
||||
FROM playlist_entries pe JOIN session_playlists sp USING (playlist_id)
|
||||
WHERE tema_id = :tema_id AND playlist_type = :playlist_type
|
||||
) s
|
||||
ON p.playlist_id == s.playlist_id AND p.set_id == s.set_id
|
||||
WHERE tema_id != :tema_id
|
||||
GROUP BY tema_id
|
||||
) common JOIN temes t ON common.tema_id == t.id
|
||||
"""
|
||||
data = dict(tema_id=tema_id, playlist_type=PlaylistType.SESSION_SETLIST.value)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
result_rows: list[CommonlyPlayedTuneRow] = cur.fetchall()
|
||||
return [
|
||||
temes_model.CommonlyPlayedTema(
|
||||
tema=row_to_tema(row[:6]),
|
||||
count=row[6],
|
||||
) for row in result_rows
|
||||
]
|
||||
@@ -14,7 +14,7 @@ def sessio_en_directe(request: Request):
|
||||
raise RuntimeError("Got a session without id!")
|
||||
|
||||
current_set = None
|
||||
if playlist := playlists_service.get_playlist(session_id=session.id):
|
||||
if playlist := service.get_session_setlist(session_id=session.id):
|
||||
if playlist.sets:
|
||||
current_set = playlists_service.add_temes_to_set(playlist.sets[-1])
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from fastapi import Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from folkugat_web.model.pagines import Pages
|
||||
from folkugat_web.services import playlists as playlists_service
|
||||
from folkugat_web.services import sessions as sessions_service
|
||||
from folkugat_web.services.temes import query as query_service
|
||||
@@ -8,31 +7,35 @@ from folkugat_web.services.temes import search as search_service
|
||||
from folkugat_web.templates import templates
|
||||
|
||||
|
||||
def add_set(request: Request, session_id: int, logged_in: bool):
|
||||
new_set = playlists_service.add_set(session_id=session_id)
|
||||
def add_set(
|
||||
request: Request,
|
||||
playlist_id: int,
|
||||
logged_in: bool,
|
||||
):
|
||||
new_set = playlists_service.add_set(playlist_id=playlist_id)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/set_entry.html",
|
||||
"fragments/playlist/set_entry.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"new_entry": True,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": new_set.id,
|
||||
"set_entry": new_set,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_set(request: Request, session_id: int, set_id: int, logged_in: bool):
|
||||
set_entry = playlists_service.get_set(session_id=session_id, set_id=set_id)
|
||||
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/sessio/set_entry.html",
|
||||
"fragments/playlist/set_entry.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"new_entry": True,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": set_id,
|
||||
"set_entry": set_entry,
|
||||
}
|
||||
@@ -41,59 +44,59 @@ def get_set(request: Request, session_id: int, set_id: int, logged_in: bool):
|
||||
return HTMLResponse()
|
||||
|
||||
|
||||
def delete_set(session_id: int, set_id: int):
|
||||
playlists_service.delete_set(session_id=session_id, set_id=set_id)
|
||||
def delete_set(playlist_id: int, set_id: int):
|
||||
playlists_service.delete_set(playlist_id=playlist_id, set_id=set_id)
|
||||
return HTMLResponse()
|
||||
|
||||
|
||||
def add_tema(request: Request, session_id: int, set_id: int, logged_in: bool):
|
||||
new_tema = playlists_service.add_tema(session_id=session_id, set_id=set_id)
|
||||
playlists_service.add_tema_to_tema_in_set(new_tema)
|
||||
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/sessio/tema_editor.html",
|
||||
"fragments/playlist/tema_editor.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": set_id,
|
||||
"tema_entry": new_tema,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_tema(request: Request, session_id: int, set_id: int, entry_id: int, logged_in: bool):
|
||||
def get_tema(request: Request, playlist_id: int, set_id: int, entry_id: int, logged_in: bool):
|
||||
tema_entry = playlists_service.get_tema(entry_id=entry_id)
|
||||
playlists_service.add_tema_to_tema_in_set(tema_entry)
|
||||
tema_entry = playlists_service.add_tema_to_tema_in_set(tema_entry)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/tema_entry.html",
|
||||
"fragments/playlist/tema_entry.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": set_id,
|
||||
"tema_entry": tema_entry,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_tema_editor(request: Request, session_id: int, set_id: int, entry_id: int, logged_in: bool):
|
||||
def get_tema_editor(request: Request, playlist_id: int, set_id: int, entry_id: int, logged_in: bool):
|
||||
tema_entry = playlists_service.get_tema(entry_id=entry_id)
|
||||
playlists_service.add_tema_to_tema_in_set(tema_entry)
|
||||
tema_entry = playlists_service.add_tema_to_tema_in_set(tema_entry)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/tema_editor.html",
|
||||
"fragments/playlist/tema_editor.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": set_id,
|
||||
"tema_entry": tema_entry,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def delete_tema(session_id: int, set_id: int, entry_id: int):
|
||||
def delete_tema(playlist_id: int, set_id: int, entry_id: int):
|
||||
playlists_service.delete_tema(entry_id=entry_id)
|
||||
if not playlists_service.get_set(session_id=session_id, set_id=set_id):
|
||||
if not playlists_service.get_set(playlist_id=playlist_id, set_id=set_id):
|
||||
headers = {
|
||||
"HX-Trigger": f"reload-set-{set_id}"
|
||||
}
|
||||
@@ -104,7 +107,7 @@ def delete_tema(session_id: int, set_id: int, entry_id: int):
|
||||
|
||||
def busca_tema(
|
||||
request: Request,
|
||||
session_id: int,
|
||||
playlist_id: int,
|
||||
set_id: int,
|
||||
entry_id: int,
|
||||
query: str,
|
||||
@@ -114,7 +117,7 @@ def busca_tema(
|
||||
if not query:
|
||||
# If there is no query, suggest tunes commonly played together
|
||||
set_entry = playlists_service.get_set(
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
)
|
||||
if set_entry:
|
||||
@@ -124,7 +127,7 @@ def busca_tema(
|
||||
commonly_played_tema_ids = {
|
||||
cpt.tema.id
|
||||
for tema_id in tema_ids
|
||||
for cpt in playlists_service.get_commonly_played_temes(tema_id)
|
||||
for cpt in sessions_service.get_commonly_played_temes(tema_id)
|
||||
if cpt.tema.id is not None
|
||||
} - tema_ids
|
||||
suggestions = query_service.get_temes_by_ids(
|
||||
@@ -141,10 +144,10 @@ def busca_tema(
|
||||
offset=0,
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/tema_results.html",
|
||||
"fragments/playlist/tema_results.html",
|
||||
{
|
||||
"request": request,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": set_id,
|
||||
"entry_id": entry_id,
|
||||
"results": suggestions,
|
||||
@@ -153,16 +156,16 @@ def busca_tema(
|
||||
)
|
||||
|
||||
|
||||
def set_tema(request: Request, logged_in: bool, session_id: int, set_id: int, entry_id: int, tema_id: int | None):
|
||||
playlists_service.set_tema(session_id=session_id, set_id=set_id, entry_id=entry_id, tema_id=tema_id)
|
||||
def set_tema(request: Request, logged_in: bool, playlist_id: int, set_id: int, entry_id: int, tema_id: int | None):
|
||||
playlists_service.set_tema(playlist_id=playlist_id, set_id=set_id, entry_id=entry_id, tema_id=tema_id)
|
||||
tema_entry = playlists_service.get_tema(entry_id=entry_id)
|
||||
playlists_service.add_tema_to_tema_in_set(tema_entry)
|
||||
tema_entry = playlists_service.add_tema_to_tema_in_set(tema_entry)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/tema_entry.html",
|
||||
"fragments/playlist/tema_entry.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"session_id": session_id,
|
||||
"playlist_id": playlist_id,
|
||||
"set_id": set_id,
|
||||
"tema_entry": tema_entry,
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
from fastapi import Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from folkugat_web.model.pagines import Pages
|
||||
from folkugat_web.services import playlists as playlists_service
|
||||
from folkugat_web.services import sessions as sessions_service
|
||||
from folkugat_web.services.temes import query as query_service
|
||||
from folkugat_web.services.temes import search as search_service
|
||||
from folkugat_web.templates import templates
|
||||
|
||||
|
||||
|
||||
30
folkugat_web/fragments/sessio/notes.py
Normal file
30
folkugat_web/fragments/sessio/notes.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from fastapi import Request
|
||||
from folkugat_web.services import sessions as sessions_service
|
||||
from folkugat_web.templates import templates
|
||||
|
||||
|
||||
def notes(request: Request, session_id: int, logged_in: bool):
|
||||
session = sessions_service.get_session(session_id=session_id)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/notes.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"session_id": session_id,
|
||||
"session": session,
|
||||
"notes": session.notes if session and session.notes else "",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def notes_editor(request: Request, session_id: int):
|
||||
session = sessions_service.get_session(session_id=session_id)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/notes_editor.html",
|
||||
{
|
||||
"request": request,
|
||||
"session_id": session_id,
|
||||
"notes": session.notes if session and session.notes else "",
|
||||
"max": max,
|
||||
}
|
||||
)
|
||||
@@ -9,8 +9,7 @@ def pagina(request: Request, session_id: int, logged_in: bool):
|
||||
session = sessions_service.get_session(session_id=session_id)
|
||||
if not session:
|
||||
raise HTTPException(status_code=404, detail="Could not find session")
|
||||
playlist = playlists_service.get_playlist(session_id=session_id)
|
||||
playlist = playlists_service.add_temes_to_playlist(playlist)
|
||||
session = sessions_service.add_playlists_to_session(session=session)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/pagina.html",
|
||||
{
|
||||
@@ -19,7 +18,6 @@ def pagina(request: Request, session_id: int, logged_in: bool):
|
||||
"Pages": Pages,
|
||||
"session_id": session_id,
|
||||
"session": session,
|
||||
"playlist": playlist,
|
||||
"date_names": sessions_service.get_date_names,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -6,22 +6,20 @@ from folkugat_web.services import sessions as sessions_service
|
||||
from folkugat_web.templates import templates
|
||||
|
||||
|
||||
async def pagina(request: Request, session_id: int, set_id: int, logged_in: bool):
|
||||
session = sessions_service.get_session(session_id=session_id)
|
||||
set_ = playlists_service.get_set(session_id=session_id, set_id=set_id)
|
||||
async def pagina(request: Request, playlist_id: int, set_id: int, logged_in: bool):
|
||||
set_ = playlists_service.get_set(playlist_id=playlist_id, set_id=set_id)
|
||||
if not set_:
|
||||
raise HTTPException(status_code=404, detail="Set not found")
|
||||
set_ = playlists_service.add_temes_to_set(set_)
|
||||
set_ = await playlists_service.add_set_score_to_set(set_)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/set/pagina.html",
|
||||
"fragments/playlist/set/pagina.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
"Pages": Pages,
|
||||
"session_id": session_id,
|
||||
"session": session,
|
||||
"set": set_,
|
||||
"session": None,
|
||||
"date_names": sessions_service.get_date_names,
|
||||
"LinkType": LinkType,
|
||||
"ContentType": ContentType,
|
||||
@@ -33,12 +31,12 @@ async def live(request: Request, logged_in: bool):
|
||||
session = sessions_service.get_live_session()
|
||||
set_ = None
|
||||
if session and session.id:
|
||||
playlist = playlists_service.get_playlist(session_id=session.id)
|
||||
if playlist.sets:
|
||||
playlist = sessions_service.get_session_setlist(session_id=session.id)
|
||||
if playlist and playlist.sets:
|
||||
set_ = playlists_service.add_temes_to_set(playlist.sets[-1])
|
||||
set_ = await playlists_service.add_set_score_to_set(set_)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/set/pagina.html",
|
||||
"fragments/playlist/set/pagina.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
@@ -56,12 +54,12 @@ async def live_set(request: Request, logged_in: bool):
|
||||
session = sessions_service.get_live_session()
|
||||
set_ = None
|
||||
if session and session.id:
|
||||
playlist = playlists_service.get_playlist(session_id=session.id)
|
||||
if playlist.sets:
|
||||
playlist = sessions_service.get_session_setlist(session_id=session.id)
|
||||
if playlist and playlist.sets:
|
||||
set_ = playlists_service.add_temes_to_set(playlist.sets[-1])
|
||||
set_ = await playlists_service.add_set_score_to_set(set_)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/sessio/set/set_page.html",
|
||||
"fragments/playlist/set/set_page.html",
|
||||
{
|
||||
"request": request,
|
||||
"logged_in": logged_in,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import dataclasses
|
||||
import enum
|
||||
from collections.abc import Iterator
|
||||
from typing import Self
|
||||
|
||||
@@ -6,10 +7,15 @@ from folkugat_web.model.temes import Tema
|
||||
from folkugat_web.utils import groupby
|
||||
|
||||
|
||||
class PlaylistType(enum.Enum):
|
||||
SESSION_SETLIST = "session_setlist"
|
||||
SESSION_SLOWJAM = "session_slowjam"
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class PlaylistEntry:
|
||||
id: int | None
|
||||
session_id: int
|
||||
playlist_id: int
|
||||
set_id: int
|
||||
tema_id: int | None
|
||||
|
||||
@@ -20,17 +26,21 @@ class TemaInSet:
|
||||
tema_id: int | None
|
||||
tema: Tema | None
|
||||
|
||||
def to_playlist_entry(self, session_id: int, set_id: int) -> PlaylistEntry:
|
||||
def to_playlist_entry(self, playlist_id: int, set_id: int) -> PlaylistEntry:
|
||||
return PlaylistEntry(
|
||||
id=self.id,
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=set_id,
|
||||
tema_id=self.tema_id,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_playlist_entry(cls, entry: PlaylistEntry) -> Self:
|
||||
return cls(id=entry.id, tema_id=entry.tema_id, tema=None)
|
||||
return cls(
|
||||
id=entry.id,
|
||||
tema_id=entry.tema_id,
|
||||
tema=None,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
@@ -45,10 +55,10 @@ class Set:
|
||||
temes: list[TemaInSet]
|
||||
score: SetScore | None
|
||||
|
||||
def to_playlist_entries(self, session_id: int) -> Iterator[PlaylistEntry]:
|
||||
def to_playlist_entries(self, playlist_id: int) -> Iterator[PlaylistEntry]:
|
||||
for tema_in_set in self.temes:
|
||||
yield tema_in_set.to_playlist_entry(
|
||||
session_id=session_id,
|
||||
playlist_id=playlist_id,
|
||||
set_id=self.id,
|
||||
)
|
||||
|
||||
@@ -58,26 +68,29 @@ class Set:
|
||||
raise ValueError("All PlaylistEntries must have the same session_id")
|
||||
return cls(
|
||||
id=set_id,
|
||||
temes=[TemaInSet.from_playlist_entry(entry) for entry in sorted(entries, key=lambda e: e.id or 0)],
|
||||
temes=[
|
||||
TemaInSet.from_playlist_entry(entry)
|
||||
for entry in sorted(entries, key=lambda e: e.id or 0)
|
||||
],
|
||||
score=None,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Playlist:
|
||||
session_id: int
|
||||
id: int
|
||||
sets: list[Set]
|
||||
|
||||
def to_playlist_entries(self) -> Iterator[PlaylistEntry]:
|
||||
for set_entry in self.sets:
|
||||
yield from set_entry.to_playlist_entries(session_id=self.session_id)
|
||||
yield from set_entry.to_playlist_entries(playlist_id=self.id)
|
||||
|
||||
@classmethod
|
||||
def from_playlist_entries(cls, session_id: int, entries: list[PlaylistEntry]) -> Self:
|
||||
if any(entry.session_id != session_id for entry in entries):
|
||||
raise ValueError("All PlaylistEntries must have the same session_id")
|
||||
def from_playlist_entries(cls, playlist_id: int, entries: list[PlaylistEntry]) -> Self:
|
||||
if any(entry.playlist_id != playlist_id for entry in entries):
|
||||
raise ValueError("All PlaylistEntries must have the same playlist_id")
|
||||
return cls(
|
||||
session_id=session_id,
|
||||
id=playlist_id,
|
||||
sets=[
|
||||
Set.from_playlist_entries(set_id, set_entries)
|
||||
for set_id, set_entries in groupby(entries, key_fn=lambda e: e.set_id, group_fn=list)
|
||||
|
||||
@@ -2,6 +2,8 @@ import dataclasses
|
||||
import datetime
|
||||
import enum
|
||||
|
||||
from folkugat_web.model import playlists
|
||||
|
||||
DEFAULT_START_TIME = datetime.time(20, 30)
|
||||
DEFAULT_END_TIME = datetime.time(22, 30)
|
||||
|
||||
@@ -21,6 +23,8 @@ class Session:
|
||||
venue: SessionVenue = dataclasses.field(default_factory=SessionVenue)
|
||||
notes: str | None = None
|
||||
cartell_url: str | None = None
|
||||
slowjam: playlists.Playlist | None = None
|
||||
setlist: playlists.Playlist | None = None
|
||||
is_live: bool = False
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,15 @@ import dataclasses
|
||||
import datetime
|
||||
import enum
|
||||
import itertools
|
||||
from typing import Self
|
||||
from typing import TYPE_CHECKING, Self
|
||||
|
||||
from folkugat_web.model.lilypond.processing import RenderError
|
||||
from folkugat_web.model.search import NGrams
|
||||
from folkugat_web.model.sessions import Session
|
||||
from folkugat_web.services import ngrams
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from folkugat_web.model.sessions import Session
|
||||
|
||||
|
||||
class ContentType(enum.Enum):
|
||||
PARTITURA = "partitura"
|
||||
|
||||
@@ -5,7 +5,6 @@ from folkugat_web.dal.sql._connection import get_connection
|
||||
from folkugat_web.dal.sql.playlists import query, write
|
||||
from folkugat_web.log import logger
|
||||
from folkugat_web.model import playlists
|
||||
from folkugat_web.model import temes as temes_model
|
||||
from folkugat_web.model.lilypond import score as lilypond_model
|
||||
from folkugat_web.services import files as files_service
|
||||
from folkugat_web.services.lilypond import build as lilypond_build
|
||||
@@ -41,37 +40,37 @@ def add_tema_to_tema_in_set(tema_in_set: playlists.TemaInSet) -> playlists.TemaI
|
||||
return tema_in_set
|
||||
|
||||
|
||||
def get_playlist(session_id: int, con: Connection | None = None) -> playlists.Playlist:
|
||||
def get_playlist(playlist_id: int, con: Connection | None = None) -> playlists.Playlist:
|
||||
return playlists.Playlist.from_playlist_entries(
|
||||
session_id=session_id,
|
||||
entries=list(query.get_playlist_entries(session_id=session_id, con=con))
|
||||
playlist_id=playlist_id,
|
||||
entries=list(query.get_playlist_entries(playlist_id=playlist_id, con=con))
|
||||
)
|
||||
|
||||
|
||||
def add_set(session_id: int, con: Connection | None = None) -> playlists.Set:
|
||||
def add_set(playlist_id: int, con: Connection | None = None) -> playlists.Set:
|
||||
with get_connection(con) as con:
|
||||
curr_playlist = get_playlist(session_id=session_id, con=con)
|
||||
curr_playlist = get_playlist(playlist_id=playlist_id, con=con)
|
||||
new_set_id = max([set_entry.id for set_entry in curr_playlist.sets], default=0) + 1
|
||||
new_entry = playlists.PlaylistEntry(id=None, session_id=session_id, set_id=new_set_id, tema_id=None)
|
||||
new_entry = playlists.PlaylistEntry(id=None, playlist_id=playlist_id, set_id=new_set_id, tema_id=None)
|
||||
inserted_entry = write.insert_playlist_entry(new_entry)
|
||||
return playlists.Set.from_playlist_entries(set_id=inserted_entry.set_id, entries=[inserted_entry])
|
||||
|
||||
|
||||
def get_set(session_id: int, set_id: int, con: Connection | None = None) -> playlists.Set | None:
|
||||
entries = list(query.get_playlist_entries(session_id=session_id, set_id=set_id, con=con))
|
||||
def get_set(playlist_id: int, set_id: int, con: Connection | None = None) -> playlists.Set | None:
|
||||
entries = list(query.get_playlist_entries(playlist_id=playlist_id, set_id=set_id, con=con))
|
||||
if entries:
|
||||
return playlists.Set.from_playlist_entries(set_id=set_id, entries=entries)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def delete_set(session_id: int, set_id: int, con: Connection | None = None):
|
||||
write.delete_playlist_set(session_id=session_id, set_id=set_id, con=con)
|
||||
def delete_set(playlist_id: int, set_id: int, con: Connection | None = None):
|
||||
write.delete_playlist_set(playlist_id=playlist_id, set_id=set_id, con=con)
|
||||
|
||||
|
||||
def add_tema(session_id: int, set_id: int, con: Connection | None = None) -> playlists.TemaInSet:
|
||||
def add_tema(playlist_id: int, set_id: int, con: Connection | None = None) -> playlists.TemaInSet:
|
||||
with get_connection(con) as con:
|
||||
new_entry = playlists.PlaylistEntry(id=None, session_id=session_id, set_id=set_id, tema_id=None)
|
||||
new_entry = playlists.PlaylistEntry(id=None, playlist_id=playlist_id, set_id=set_id, tema_id=None)
|
||||
inserted_entry = write.insert_playlist_entry(new_entry)
|
||||
return playlists.TemaInSet.from_playlist_entry(inserted_entry)
|
||||
|
||||
@@ -87,10 +86,10 @@ def delete_tema(entry_id: int, con: Connection | None = None):
|
||||
write.delete_playlist_entry(entry_id=entry_id, con=con)
|
||||
|
||||
|
||||
def set_tema(session_id: int, set_id: int, entry_id: int, tema_id: int | None,
|
||||
def set_tema(playlist_id: int, set_id: int, entry_id: int, tema_id: int | None,
|
||||
con: Connection | None = None):
|
||||
with get_connection(con) as con:
|
||||
new_entry = playlists.PlaylistEntry(id=entry_id, session_id=session_id, set_id=set_id, tema_id=tema_id)
|
||||
new_entry = playlists.PlaylistEntry(id=entry_id, playlist_id=playlist_id, set_id=set_id, tema_id=tema_id)
|
||||
write.update_playlist_entry(entry=new_entry, con=con)
|
||||
|
||||
|
||||
@@ -163,9 +162,3 @@ async def add_set_score_to_set(tune_set: playlists.Set) -> playlists.Set:
|
||||
)
|
||||
else:
|
||||
return tune_set
|
||||
|
||||
|
||||
def get_commonly_played_temes(
|
||||
tema_id: int,
|
||||
) -> list[temes_model.CommonlyPlayedTema]:
|
||||
return query.get_commonly_played_tunes(tema_id=tema_id)
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import dataclasses
|
||||
import datetime
|
||||
from datetime import date as Date
|
||||
|
||||
from folkugat_web.config import date as config
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.dal.sql.sessions import playlists as session_playlists
|
||||
from folkugat_web.dal.sql.sessions import query, write
|
||||
from folkugat_web.model import sessions as model
|
||||
from folkugat_web.model import temes as temes_model
|
||||
from folkugat_web.model.playlists import Playlist, PlaylistType
|
||||
from folkugat_web.model.sql import Order, OrderCol, Range
|
||||
from folkugat_web.services import playlists as playlists_service
|
||||
|
||||
|
||||
def get_date_names(date: Date) -> model.DateNames:
|
||||
@@ -77,3 +83,80 @@ def stop_live_sessions():
|
||||
|
||||
def set_live_session(session_id: int):
|
||||
write.set_live_session(session_id=session_id)
|
||||
|
||||
|
||||
def get_session_playlist_id(
|
||||
session_id: int,
|
||||
playlist_type: PlaylistType,
|
||||
con: Connection | None = None,
|
||||
) -> int | None:
|
||||
with get_connection(con=con) as con:
|
||||
return session_playlists.get_playlist_id(
|
||||
session_id=session_id,
|
||||
playlist_type=playlist_type,
|
||||
con=con,
|
||||
)
|
||||
|
||||
|
||||
def get_session_playlist(
|
||||
session_id: int,
|
||||
playlist_type: PlaylistType,
|
||||
con: Connection | None = None,
|
||||
) -> Playlist | None:
|
||||
with get_connection(con=con) as con:
|
||||
playlist_id = get_session_playlist_id(
|
||||
session_id=session_id,
|
||||
playlist_type=playlist_type,
|
||||
con=con,
|
||||
)
|
||||
if playlist_id is None:
|
||||
return None
|
||||
return playlists_service.get_playlist(
|
||||
playlist_id=playlist_id,
|
||||
con=con,
|
||||
)
|
||||
|
||||
|
||||
def get_session_setlist(
|
||||
session_id: int,
|
||||
con: Connection | None = None,
|
||||
) -> Playlist | None:
|
||||
return get_session_playlist(
|
||||
session_id=session_id,
|
||||
playlist_type=PlaylistType.SESSION_SETLIST,
|
||||
con=con,
|
||||
)
|
||||
|
||||
|
||||
def get_session_slowjam(
|
||||
session_id: int,
|
||||
con: Connection | None = None,
|
||||
) -> Playlist | None:
|
||||
return get_session_playlist(
|
||||
session_id=session_id,
|
||||
playlist_type=PlaylistType.SESSION_SLOWJAM,
|
||||
con=con,
|
||||
)
|
||||
|
||||
|
||||
def add_playlists_to_session(session: model.Session) -> model.Session:
|
||||
if session.id is not None:
|
||||
with get_connection() as con:
|
||||
setlist = get_session_setlist(session_id=session.id, con=con)
|
||||
if setlist:
|
||||
setlist = playlists_service.add_temes_to_playlist(setlist)
|
||||
slowjam = get_session_slowjam(session_id=session.id, con=con)
|
||||
if slowjam:
|
||||
slowjam = playlists_service.add_temes_to_playlist(slowjam)
|
||||
session = dataclasses.replace(
|
||||
session,
|
||||
setlist=setlist,
|
||||
slowjam=slowjam,
|
||||
)
|
||||
return session
|
||||
|
||||
|
||||
def get_commonly_played_temes(
|
||||
tema_id: int,
|
||||
) -> list[temes_model.CommonlyPlayedTema]:
|
||||
return session_playlists.get_commonly_played_tunes(tema_id=tema_id)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from collections.abc import Iterable
|
||||
|
||||
from folkugat_web.dal.sql.playlists import query as playlists_q
|
||||
from folkugat_web.dal.sql.sessions import playlists as session_playlists
|
||||
from folkugat_web.dal.sql.temes import query as temes_q
|
||||
from folkugat_web.model import sessions as sessions_model
|
||||
from folkugat_web.model import temes as model
|
||||
@@ -20,7 +20,7 @@ def tema_compute_stats(
|
||||
) -> model.Tema:
|
||||
if tema.id:
|
||||
if tune_sessions_dict is None:
|
||||
tune_sessions_dict = playlists_q.get_tune_sessions(tema_ids=[tema.id])
|
||||
tune_sessions_dict = session_playlists.get_tune_sessions(tema_ids=[tema.id])
|
||||
if tema.id and (tune_sessions := tune_sessions_dict.get(tema.id)):
|
||||
unique_tune_sessions = set(tune_sessions)
|
||||
tema.stats = model.Stats(
|
||||
@@ -33,7 +33,7 @@ def tema_compute_stats(
|
||||
def temes_compute_stats(temes: Iterable[model.Tema]) -> list[model.Tema]:
|
||||
temes = list(temes)
|
||||
tema_ids = [tema.id for tema in temes if tema.id is not None]
|
||||
tune_sessions_dict = playlists_q.get_tune_sessions(tema_ids=tema_ids)
|
||||
tune_sessions_dict = session_playlists.get_tune_sessions(tema_ids=tema_ids)
|
||||
return [tema_compute_stats(tema=tema, tune_sessions_dict=tune_sessions_dict) for tema in temes]
|
||||
|
||||
|
||||
@@ -41,5 +41,5 @@ def tema_compute_played_with(
|
||||
tema: model.Tema,
|
||||
) -> model.Tema:
|
||||
if tema.id:
|
||||
tema.played_with = playlists_q.get_commonly_played_tunes(tema_id=tema.id)
|
||||
tema.played_with = session_playlists.get_commonly_played_tunes(tema_id=tema.id)
|
||||
return tema
|
||||
|
||||
57
scripts/05_migrate_playlists.py
Normal file
57
scripts/05_migrate_playlists.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from folkugat_web.dal.sql import get_connection
|
||||
from folkugat_web.dal.sql.playlists import write as playlists_w
|
||||
from folkugat_web.dal.sql.playlists.ddl import (create_playlist_entries_table,
|
||||
create_playlists_table)
|
||||
from folkugat_web.dal.sql.sessions import playlists as session_playlists
|
||||
from folkugat_web.dal.sql.sessions import query as sessions_q
|
||||
from folkugat_web.dal.sql.sessions.ddl import create_session_playlists_table
|
||||
from folkugat_web.model.playlists import PlaylistType
|
||||
|
||||
with get_connection() as con:
|
||||
cur = con.cursor()
|
||||
|
||||
drop_query = """DROP TABLE rehearse_data"""
|
||||
_ = cur.execute(drop_query)
|
||||
|
||||
alter_query = """ALTER TABLE playlists RENAME TO playlists_old"""
|
||||
_ = cur.execute(alter_query)
|
||||
|
||||
# Create new tables
|
||||
create_playlist_entries_table(con=con)
|
||||
create_playlists_table(con=con)
|
||||
create_session_playlists_table(con=con)
|
||||
|
||||
# Create new playlists
|
||||
sessions = sessions_q.get_sessions(con=con)
|
||||
for session in sessions:
|
||||
if session.id is None:
|
||||
raise ValueError("Session without id!")
|
||||
|
||||
setlist_id = playlists_w.create_playlist(con=con)
|
||||
session_playlists.insert_playlist(
|
||||
session_id=session.id,
|
||||
playlist_type=PlaylistType.SESSION_SETLIST,
|
||||
playlist_id=setlist_id,
|
||||
con=con,
|
||||
)
|
||||
|
||||
slowjam_id = playlists_w.create_playlist(con=con)
|
||||
session_playlists.insert_playlist(
|
||||
session_id=session.id,
|
||||
playlist_type=PlaylistType.SESSION_SLOWJAM,
|
||||
playlist_id=slowjam_id,
|
||||
con=con,
|
||||
)
|
||||
|
||||
# Migrate
|
||||
migrate_query = """
|
||||
INSERT INTO playlist_entries
|
||||
(id, playlist_id, set_id, tema_id)
|
||||
SELECT
|
||||
NULL, sp.playlist_id, pl_old.set_id, pl_old.tema_id
|
||||
FROM playlists_old pl_old JOIN session_playlists sp USING (session_id)
|
||||
WHERE sp.playlist_type = "session_setlist"
|
||||
"""
|
||||
_ = cur.execute(migrate_query)
|
||||
|
||||
print("DONE!")
|
||||
Reference in New Issue
Block a user