From 52a6ae12e9c3fbdfc9b8594a8a2177de9e60600f Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Sat, 12 Apr 2025 09:32:54 -0400 Subject: [PATCH] Add main jams page --- src/littlesongplace/jams.py | 25 ++++++++++++++-- src/littlesongplace/templates/jam.html | 9 ++---- src/littlesongplace/templates/jams-main.html | 31 ++++++++++++++++++++ test/test_jams.py | 5 ++++ 4 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 src/littlesongplace/templates/jams-main.html diff --git a/src/littlesongplace/jams.py b/src/littlesongplace/jams.py index 71cbc42..771340e 100644 --- a/src/littlesongplace/jams.py +++ b/src/littlesongplace/jams.py @@ -8,10 +8,20 @@ from .sanitize import sanitize_user_text bp = Blueprint("jams", __name__, url_prefix="/jams") + @bp.get("/") def jams(): - # Show a list of all jams (or events?): current, upcoming, previous - ... + # Show a list of all jams: ongoing, upcoming, previous + rows = db.query( + """ + SELECT * FROM jams + INNER JOIN users ON jams.ownerid = users.userid + """) + jams = [Jam.from_row(r) for r in rows] + + # TODO: Sort into groups based on start/end dates + return render_template("jams-main.html", ongoing=jams, upcoming=[], past=[]) + @bp.get("/create") @auth.requires_login @@ -28,6 +38,7 @@ def create(): jamid = row["jamid"] return redirect(url_for("jams.jam", jamid=jamid)) + @bp.get("/") def jam(jamid): row = db.query( @@ -41,6 +52,7 @@ def jam(jamid): # Show the main jam page return render_template("jam.html", jam=jam) + @bp.post("//update") @auth.requires_login def update(jamid): @@ -58,6 +70,7 @@ def update(jamid): db.commit() return redirect(url_for("jams.jam", jamid=jamid)) + @bp.get("//delete") @auth.requires_login def delete(jamid): @@ -69,34 +82,40 @@ def delete(jamid): db.commit() return redirect(url_for("jams.jams")) + @bp.get("//events") def events(jamid): # Show a list of all events for the jam (current, upcoming, previous) ... + @bp.get("//events/create") @auth.requires_login def events_create(): # Create a new event and redirect to the edit form ... + @bp.get("//events/") def events_view(eventid): # Show the event page ... + @bp.post("//events//update") @auth.requires_login def events_update(jamid): # Update an event with the new form data ... + @bp.get("//events//delete") @auth.requires_login def events_delete(jamid): # Delete an event, redirect to list of all events ... + @dataclass class Jam: jamid: int @@ -123,6 +142,7 @@ class Jam: events=events, ) + @dataclass class JamEvent: eventid: int @@ -151,3 +171,4 @@ class JamEvent: # TODO: Comment object? comments=comments, ) + diff --git a/src/littlesongplace/templates/jam.html b/src/littlesongplace/templates/jam.html index f6f5fe3..4704f54 100644 --- a/src/littlesongplace/templates/jam.html +++ b/src/littlesongplace/templates/jam.html @@ -6,17 +6,12 @@

{{ jam.title }}

- -
- Posted By: {{ jam.userid }} -
- Deadline: {{ jam.enddate }} + Jam Master: {{ jam.username }}
-

Description

-
+

Description

{{ jam.description }}
diff --git a/src/littlesongplace/templates/jams-main.html b/src/littlesongplace/templates/jams-main.html new file mode 100644 index 0000000..7144d4d --- /dev/null +++ b/src/littlesongplace/templates/jams-main.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} + +{% block title %}Jams{% endblock %} + +{% block body %} + +

Jams

+ +{% macro jam_list(list_title, jams) %} +{% if jams %} +

{{ list_title }}

+
+ {% for jam in jams %} +
+ + {{ jam.title }} + + + Hosted by {{ jam.username }} + +
+ {% endfor %} +
+{% endif %} +{% endmacro %} + +{{ jam_list("Ongoing Jams", ongoing) }} +{{ jam_list("Upcoming Jams", upcoming) }} +{{ jam_list("Past Jams", past) }} + +{% endblock %} diff --git a/test/test_jams.py b/test/test_jams.py index cda7c96..7fa1d41 100644 --- a/test/test_jams.py +++ b/test/test_jams.py @@ -22,6 +22,11 @@ def test_create_jam(client, user): assert response.request.path == "/jams/1" assert b"New Jam" in response.data +def test_jams_list(client, user, jam): + response = client.get("/jams/") + assert response.status_code == 200 + assert b"New Jam" in response.data + def test_update_jam(client, user, jam): response = client.post( f"/jams/{jam}/update", -- 2.39.5