change to the buchungs system
This commit is contained in:
+37
-29
@@ -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'])
|
||||
@login_required
|
||||
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:
|
||||
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()
|
||||
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)
|
||||
|
||||
# Start async worker passing prov_id
|
||||
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()
|
||||
if not tenant_slug:
|
||||
return jsonify({"success": False, "error": "Ungültige Subdomain angegeben."}), 400
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"tenant_slug": tenant_slug,
|
||||
"request_id": prov_id
|
||||
}), 200
|
||||
# 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,
|
||||
"request_id": prov_id
|
||||
}), 200
|
||||
|
||||
except Exception as e:
|
||||
# WICHTIG: Fängt jegliche Python-Fehler ab und sendet sauberes JSON statt HTML-Crash
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
@app.route('/instance_request/status')
|
||||
def tenant_status():
|
||||
|
||||
@@ -481,20 +481,23 @@
|
||||
body: formData,
|
||||
headers: { 'Accept': 'application/json' }
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
// Prüfen, ob der Server echtes JSON zurückgibt
|
||||
const contentType = response.headers.get("content-type");
|
||||
let result;
|
||||
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.");
|
||||
}
|
||||
|
||||
if (!response.ok || !result.success) {
|
||||
throw new Error(result.error || 'Es gab ein Problem bei der Buchung.');
|
||||
}
|
||||
|
||||
// Erfolg: Formular verstecken, Ladebildschirm zeigen
|
||||
formState.style.display = 'none';
|
||||
loadingState.style.display = 'block';
|
||||
|
||||
// Starte Polling
|
||||
startPolling(tenantSlug);
|
||||
|
||||
} catch (error) {
|
||||
errorAlert.textContent = error.message;
|
||||
errorAlert.style.display = 'block';
|
||||
|
||||
Reference in New Issue
Block a user