]> littlesong.place Git - littlesongplace.git/commitdiff
Add main jams page
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 12 Apr 2025 13:32:54 +0000 (09:32 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 12 Apr 2025 13:32:54 +0000 (09:32 -0400)
src/littlesongplace/jams.py
src/littlesongplace/templates/jam.html
src/littlesongplace/templates/jams-main.html [new file with mode: 0644]
test/test_jams.py

index 71cbc42d697d21e0b4db4e68bc1e8e8912d06585..771340e35d4313397adfc7a5b5030340612dac2a 100644 (file)
@@ -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("/<int:jamid>")
 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("/<int:jamid>/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("/<int:jamid>/delete")
 @auth.requires_login
 def delete(jamid):
@@ -69,34 +82,40 @@ def delete(jamid):
     db.commit()
     return redirect(url_for("jams.jams"))
 
+
 @bp.get("/<int:jamid>/events")
 def events(jamid):
     # Show a list of all events for the jam (current, upcoming, previous)
     ...
 
+
 @bp.get("/<int:jamid>/events/create")
 @auth.requires_login
 def events_create():
     # Create a new event and redirect to the edit form
     ...
 
+
 @bp.get("/<int:jamid>/events/<int:eventid>")
 def events_view(eventid):
     # Show the event page
     ...
 
+
 @bp.post("/<int:jamid>/events/<int:eventid>/update")
 @auth.requires_login
 def events_update(jamid):
     # Update an event with the new form data
     ...
 
+
 @bp.get("/<int:jamid>/events/<int:eventid>/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,
         )
+
index f6f5fe3f6b6a3c4db96399a53c85b341c1510146..4704f54eca64dfa2ea9595925336c29be4623ed9 100644 (file)
@@ -6,17 +6,12 @@
 
 <h1>{{ jam.title }}</h1>
 
-
-<div>
-    <span><strong>Posted By:</strong></span> {{ jam.userid }}
-</div>
 <div>
-    <span><strong>Deadline:</strong></span> {{ jam.enddate }}
+    <span><strong>Jam Master:</strong></span> {{ jam.username }}
 </div>
 
-<h2>Description</h2>
-
 <div>
+<h2>Description</h2>
 {{ jam.description }}
 </div>
 
diff --git a/src/littlesongplace/templates/jams-main.html b/src/littlesongplace/templates/jams-main.html
new file mode 100644 (file)
index 0000000..7144d4d
--- /dev/null
@@ -0,0 +1,31 @@
+{% extends "base.html" %}
+
+{% block title %}Jams{% endblock %}
+
+{% block body %}
+
+<h1>Jams</h1>
+
+{% macro jam_list(list_title, jams) %}
+{% if jams %}
+<h2>{{ list_title }}</h2>
+<div class="jam-list">
+    {% for jam in jams %}
+    <div class="jam-list-entry">
+        <span class="jam-list-title">
+            {{ jam.title }}
+        </span>
+        <span class="jam-list-owner">
+            Hosted by <a href="/users/{{ jam.username }}" class="profile-link">{{ jam.username }}</a>
+        </span>
+    </div>
+    {% endfor %}
+</div>
+{% endif %}
+{% endmacro %}
+
+{{ jam_list("Ongoing Jams", ongoing) }}
+{{ jam_list("Upcoming Jams", upcoming) }}
+{{ jam_list("Past Jams", past) }}
+
+{% endblock %}
index cda7c96c6a1fffc119871433416b5c2987559ddb..7fa1d417279110d077f9e0780bca53ecb6dfdfc0 100644 (file)
@@ -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",