From ca90346f0b8f68de2d6d643cc1be6c98a75283f7 Mon Sep 17 00:00:00 2001 From: Markus Zimmerberger Date: Fri, 11 Sep 2026 08:03:19 +0200 Subject: [PATCH] Add edit my rides --- app.py | 51 +++++++++++++++++++++++++++++----------- templates/add_entry.html | 40 +++++++++++++++++++------------ templates/base.html | 20 ++++++++++++++++ templates/dashboard.html | 25 +++++++++++++++++--- 4 files changed, 104 insertions(+), 32 deletions(-) diff --git a/app.py b/app.py index 23c58bd..3628e74 100644 --- a/app.py +++ b/app.py @@ -200,24 +200,25 @@ def register_routes(app): return None return stop.id if stop is not None else None + def fill_trip_from_form(fahrt): + fahrt.transport_mode = request.form["transport_mode"] + fahrt.line = request.form.get("line", "").strip() + fahrt.origin = request.form["origin"].strip() + fahrt.origin_stop_id = resolve_stop_id(request.form.get("origin_stop_id")) + fahrt.destination = request.form["destination"].strip() + fahrt.destination_stop_id = resolve_stop_id( + request.form.get("destination_stop_id") + ) + fahrt.trip_date = parse_trip_date(request.form.get("trip_date")) + fahrt.rating = int(request.form["rating"]) + fahrt.comment = request.form.get("comment", "").strip() + @app.route("/fahrt/neu", methods=["GET", "POST"]) @login_required def neue_fahrt(): if request.method == "POST": - fahrt = Trip( - user_id=current_user.id, - transport_mode=request.form["transport_mode"], - line=request.form.get("line", "").strip(), - origin=request.form["origin"].strip(), - origin_stop_id=resolve_stop_id(request.form.get("origin_stop_id")), - destination=request.form["destination"].strip(), - destination_stop_id=resolve_stop_id( - request.form.get("destination_stop_id") - ), - trip_date=parse_trip_date(request.form.get("trip_date")), - rating=int(request.form["rating"]), - comment=request.form.get("comment", "").strip(), - ) + fahrt = Trip(user_id=current_user.id) + fill_trip_from_form(fahrt) db.session.add(fahrt) db.session.commit() flash("Fahrt gespeichert.", "success") @@ -227,6 +228,28 @@ def register_routes(app): "add_entry.html", verkehrsmittel_optionen=VERKEHRSMITTEL_OPTIONEN, heute=date.today().isoformat(), + fahrt=None, + ) + + @app.route("/fahrt//bearbeiten", methods=["GET", "POST"]) + @login_required + def fahrt_bearbeiten(fahrt_id): + fahrt = Trip.query.get_or_404(fahrt_id) + if fahrt.user_id != current_user.id: + flash("Nicht erlaubt.", "error") + return redirect(url_for("dashboard")) + + if request.method == "POST": + fill_trip_from_form(fahrt) + db.session.commit() + flash("Fahrt aktualisiert.", "success") + return redirect(url_for("dashboard")) + + return render_template( + "add_entry.html", + verkehrsmittel_optionen=VERKEHRSMITTEL_OPTIONEN, + heute=fahrt.trip_date.isoformat(), + fahrt=fahrt, ) @app.route("/fahrt//loeschen", methods=["POST"]) diff --git a/templates/add_entry.html b/templates/add_entry.html index 25b5c8e..71859fa 100644 --- a/templates/add_entry.html +++ b/templates/add_entry.html @@ -1,14 +1,14 @@ {% extends "base.html" %} -{% block title %}Neue Fahrt – PBT{% endblock %} +{% block title %}{{ "Fahrt bearbeiten" if fahrt else "Neue Fahrt" }} – PBT{% endblock %} {% block content %}
-

Neue Fahrt erfassen

-
+

{{ "Fahrt bearbeiten" if fahrt else "Neue Fahrt erfassen" }}

+
@@ -17,23 +17,32 @@ - -

+ +

{{ + "✓ " ~ fahrt.origin_stop.name ~ (", " ~ fahrt.origin_stop.municipality if fahrt.origin_stop.municipality else "") + if fahrt and fahrt.origin_stop else "" }}

- -

+ +

{{ + "✓ " ~ fahrt.destination_stop.name ~ (", " ~ fahrt.destination_stop.municipality if fahrt.destination_stop.municipality else "") + if fahrt and fahrt.destination_stop else "" }}

Halte oben wählen für Linienvorschläge.

@@ -46,20 +55,21 @@
- +
- + {% endblock %} diff --git a/templates/base.html b/templates/base.html index bd8d1cb..d6ab238 100644 --- a/templates/base.html +++ b/templates/base.html @@ -136,6 +136,26 @@ .stars { color: #e3b341; white-space: nowrap; } .stop-dot { color: var(--success); font-size: 0.7rem; vertical-align: middle; } + .row-actions { display: flex; gap: 0.4rem; } + .row-actions form { display: contents; } + .icon-btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 2rem; + height: 2rem; + padding: 0; + border: 1px solid var(--panel-border); + border-radius: 6px; + background: transparent; + color: var(--text-muted); + cursor: pointer; + } + .icon-btn svg { width: 16px; height: 16px; } + .icon-btn.edit:hover { color: var(--accent); border-color: var(--accent); background: rgba(74, 158, 255, 0.1); } + .icon-btn.delete { color: var(--danger); } + .icon-btn.delete:hover { background: rgba(248, 81, 73, 0.12); border-color: var(--danger); } + .combo { position: relative; display: flex; flex-direction: column; } .combo-list { position: absolute; diff --git a/templates/dashboard.html b/templates/dashboard.html index 8d854a6..ca12289 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -32,9 +32,28 @@ {{ "★" * f.rating }}{{ "☆" * (5 - f.rating) }} -
- -
+
+ + + + + +
+ +
+
{% if f.comment %}