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
jamid = row["jamid"]
return redirect(url_for("jams.jam", jamid=jamid))
+
@bp.get("/<int:jamid>")
def jam(jamid):
row = db.query(
# Show the main jam page
return render_template("jam.html", jam=jam)
+
@bp.post("/<int:jamid>/update")
@auth.requires_login
def update(jamid):
db.commit()
return redirect(url_for("jams.jam", jamid=jamid))
+
@bp.get("/<int:jamid>/delete")
@auth.requires_login
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
events=events,
)
+
@dataclass
class JamEvent:
eventid: int
# TODO: Comment object?
comments=comments,
)
+
--- /dev/null
+{% 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 %}
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",