change to the buchungs system

This commit is contained in:
2026-08-25 14:17:32 +02:00
parent 645de54b77
commit 7c6ecd83f4
2 changed files with 51 additions and 40 deletions
+37 -29
View File
@@ -3714,38 +3714,46 @@ def run_tenant_provisioning_async(app, user_id, tenant_slug, school_name, user_e
@app.route('/booking_payment_async', methods=['POST']) @app.route('/booking_payment_async', methods=['POST'])
@login_required @login_required
def booking_payment_async(): def booking_payment_async():
user_id = session.get("user_id")
user_email = session.get("email")
tenant_slug = _slugify_subdomain(request.form.get('tenant_slug'))
school_name = request.form.get('school_name', tenant_slug)
# Insert request record into instance_requests
req_client, req_col = _get_collection("instance_requests")
try: try:
prov_doc = { user_id = session.get("user_id")
"user_id": user_id, user_email = session.get("email")
tenant_slug = _slugify_subdomain(request.form.get('tenant_slug'))
school_name = request.form.get('school_name', tenant_slug)
if not tenant_slug:
return jsonify({"success": False, "error": "Ungültige Subdomain angegeben."}), 400
# Datenbank-Eintrag erstellen...
req_client, req_col = _get_collection("instance_requests")
try:
prov_doc = {
"user_id": user_id,
"tenant_slug": tenant_slug,
"school_name": school_name,
"provision_status": "pending",
"created_at": _utc_now_iso(),
"updated_at": _utc_now_iso()
}
prov_id = str(req_col.insert_one(prov_doc).inserted_id)
finally:
req_client.close()
# Asynchronen Thread starten...
thread = threading.Thread(
target=run_tenant_provisioning_async,
args=(app._get_current_object(), user_id, tenant_slug, school_name, user_email, prov_id)
)
thread.start()
return jsonify({
"success": True,
"tenant_slug": tenant_slug, "tenant_slug": tenant_slug,
"school_name": school_name, "request_id": prov_id
"provision_status": "pending", }), 200
"created_at": _utc_now_iso(),
"updated_at": _utc_now_iso()
}
prov_id = str(req_col.insert_one(prov_doc).inserted_id)
finally:
req_client.close()
# Start async worker passing prov_id except Exception as e:
thread = threading.Thread( # WICHTIG: Fängt jegliche Python-Fehler ab und sendet sauberes JSON statt HTML-Crash
target=run_tenant_provisioning_async, return jsonify({"success": False, "error": str(e)}), 500
args=(app._get_current_object(), user_id, tenant_slug, school_name, user_email, prov_id)
)
thread.start()
return jsonify({
"success": True,
"tenant_slug": tenant_slug,
"request_id": prov_id
}), 200
@app.route('/instance_request/status') @app.route('/instance_request/status')
def tenant_status(): def tenant_status():
+13 -10
View File
@@ -482,18 +482,21 @@
headers: { 'Accept': 'application/json' } headers: { 'Accept': 'application/json' }
}); });
const result = await response.json(); // Prüfen, ob der Server echtes JSON zurückgibt
const contentType = response.headers.get("content-type");
if (!response.ok) { let result;
throw new Error(result.error || 'Es gab ein Problem bei der Buchung.'); if (contentType && contentType.includes("application/json")) {
result = await response.json();
} else {
// Wenn der Server HTML schickt (z.B. Flask Debugger Error Page)
const rawText = await response.text();
console.error("Server hat kein JSON gesendet:", rawText);
throw new Error("Ein Serverfehler ist aufgetreten. Bitte prüfen Sie die Konsolenausgabe.");
} }
// Erfolg: Formular verstecken, Ladebildschirm zeigen if (!response.ok || !result.success) {
formState.style.display = 'none'; throw new Error(result.error || 'Es gab ein Problem bei der Buchung.');
loadingState.style.display = 'block'; }
// Starte Polling
startPolling(tenantSlug);
} catch (error) { } catch (error) {
errorAlert.textContent = error.message; errorAlert.textContent = error.message;