Add valid lines to stops
Deploy PBT / deploy (push) Failing after 25s

This commit is contained in:
2026-09-10 22:45:12 +02:00
parent 158311a329
commit 3535ebcba0
9 changed files with 424 additions and 160 deletions
+37
View File
@@ -146,6 +146,43 @@ def register_routes(app):
]
)
def _line_sort_key(ref):
head = ""
i = 0
while i < len(ref) and not ref[i].isdigit():
head += ref[i]
i += 1
num = ref[i:]
digits = ""
while num and num[0].isdigit():
digits += num[0]
num = num[1:]
return (head.lower(), int(digits) if digits else -1, num.lower())
@app.route("/api/lines")
@login_required
def api_lines():
"""Line suggestions for the "Linie" field, scoped to the chosen stops."""
def stop_lines(param):
stop = db.session.get(Stop, int(param)) if (param or "").isdigit() else None
return set(stop.line_list()) if stop else set()
origin = stop_lines(request.args.get("origin_stop_id"))
destination = stop_lines(request.args.get("destination_stop_id"))
candidates = origin | destination
if not candidates:
return jsonify([])
needle = request.args.get("q", "").strip().lower()
both = origin & destination
refs = sorted(
(r for r in candidates if not needle or r.lower().startswith(needle)),
key=lambda r: (r not in both, _line_sort_key(r)),
)
return jsonify(
[{"ref": r, "both": r in both} for r in refs[:20]]
)
def parse_trip_date(raw_value):
raw_value = (raw_value or "").strip()
try: