From fade38e7a07ef06101cd024a61b0bb38fc64a3d8 Mon Sep 17 00:00:00 2001 From: Mischa Date: Sun, 21 Jun 2026 16:58:03 +0200 Subject: [PATCH] fix: enforce write phase completion gate and wire done endpoint - GET /write now checks all groups are written/skipped before showing the completion screen; incomplete sessions are redirected to the first draft group - POST /write/done now accepts form data (not JSON) and redirects to /export; wired up from the completion screen via a
POST button - phase5.html extra_scripts block wrapped in {% if group %} to prevent Jinja errors when group is None on the completion screen Co-Authored-By: Claude Sonnet 4.6 --- services/travel-memories/app/routes/write.py | 14 ++++++++++---- services/travel-memories/app/templates/phase5.html | 8 +++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/services/travel-memories/app/routes/write.py b/services/travel-memories/app/routes/write.py index c074c5f..bbba9f6 100644 --- a/services/travel-memories/app/routes/write.py +++ b/services/travel-memories/app/routes/write.py @@ -13,6 +13,11 @@ def write(): total = len(active_groups) group = active_groups[group_idx] if group_idx < total else None done_count = sum(1 for g in active_groups if g.status in ("written", "skipped")) + if group is None: + all_done = all(g.status in ("written", "skipped", "exported") for g in active_groups) + if not all_done: + first_incomplete = next(i for i, g in enumerate(active_groups) if g.status == "draft") + return redirect(url_for("write.write", album_id=album_id, group_idx=first_incomplete)) photos = [] if group: by_id = {p.id: p for p in state.photos} @@ -86,12 +91,13 @@ def skip(): @bp.post("/write/done") -def done(): - body = request.get_json() - album_id = body["album_id"] +def write_done(): + album_id = request.form["album_id"] state = load_state(album_id, current_app) + if state is None: + return jsonify({"ok": False, "error": "not found"}), 404 if "write" not in state.phases_completed: state.phases_completed.append("write") state.phase = "export" save_state(state, current_app) - return jsonify({"ok": True, "redirect": f"/export?album_id={album_id}"}) + return redirect(f"/export?album_id={album_id}") diff --git a/services/travel-memories/app/templates/phase5.html b/services/travel-memories/app/templates/phase5.html index 441d4a7..5d7363f 100644 --- a/services/travel-memories/app/templates/phase5.html +++ b/services/travel-memories/app/templates/phase5.html @@ -7,7 +7,11 @@ {% if not group %} -
All groups written or skipped. Continue to export →
+
All groups written or skipped.
+ + + + {% else %}
@@ -101,6 +105,7 @@ {% endblock %} {% block extra_scripts %} +{% if group %} +{% endif %} {% endblock %}