Refactor: Züchter-Antrag in Upgrade-Flow integriert (SW by-v925)
- /breeder/apply: Dokument jetzt optional (File(None)), kann per Mail nachgereicht werden
- _showUpgradeModal('breeder'): enthält jetzt Zwinger-Formular (Zwingername*, Rasse*,
Verein, Stadt, VDH-Checkbox, optionales Dokument)
→ sendet /breeder/apply + /auth/upgrade-request in einem Schritt
- Züchter-Profil-Karte in Settings: 'Züchter werden'-Button entfernt
→ für neue User ohne Antrag wird die Card vollständig ausgeblendet
→ 'Neu beantragen' bei Ablehnung öffnet jetzt _showUpgradeModal('breeder')
- Verifizierte Züchter: Card unverändert (Profil, Edit, KI-Settings)
This commit is contained in:
parent
a27b8ea5b4
commit
4332b1195e
5 changed files with 118 additions and 38 deletions
|
|
@ -87,7 +87,7 @@ async def breeder_apply(
|
|||
stadt: str = Form(...),
|
||||
website: str = Form(""),
|
||||
beschreibung: str = Form(""),
|
||||
dokument: UploadFile = File(...),
|
||||
dokument: UploadFile = File(None),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
with db() as conn:
|
||||
|
|
@ -103,28 +103,27 @@ async def breeder_apply(
|
|||
if row["breeder_status"] == "pending":
|
||||
raise HTTPException(400, "Du hast bereits einen offenen Antrag.")
|
||||
|
||||
# Dokument validieren und speichern
|
||||
data = await dokument.read()
|
||||
if len(data) > 10 * 1024 * 1024:
|
||||
raise HTTPException(400, "Dokument zu groß (max. 10 MB).")
|
||||
ext = os.path.splitext(dokument.filename or "")[1].lower()
|
||||
if ext not in (".pdf", ".jpg", ".jpeg", ".png", ".webp"):
|
||||
raise HTTPException(400, "Nur PDF, JPG, PNG oder WebP erlaubt.")
|
||||
|
||||
user_doc_dir = os.path.join(BREEDER_DOCS_DIR, str(user["id"]))
|
||||
os.makedirs(user_doc_dir, exist_ok=True)
|
||||
|
||||
filename = f"antrag_{datetime.now(_TZ).strftime('%Y%m%d_%H%M%S')}{ext}"
|
||||
filepath = os.path.join(user_doc_dir, filename)
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(data)
|
||||
# Dokument optional speichern
|
||||
filepath = None
|
||||
if dokument and dokument.filename:
|
||||
data = await dokument.read()
|
||||
if len(data) > 10 * 1024 * 1024:
|
||||
raise HTTPException(400, "Dokument zu groß (max. 10 MB).")
|
||||
ext = os.path.splitext(dokument.filename)[1].lower()
|
||||
if ext not in (".pdf", ".jpg", ".jpeg", ".png", ".webp"):
|
||||
raise HTTPException(400, "Nur PDF, JPG, PNG oder WebP erlaubt.")
|
||||
user_doc_dir = os.path.join(BREEDER_DOCS_DIR, str(user["id"]))
|
||||
os.makedirs(user_doc_dir, exist_ok=True)
|
||||
filename = f"antrag_{datetime.now(_TZ).strftime('%Y%m%d_%H%M%S')}{ext}"
|
||||
filepath = os.path.join(user_doc_dir, filename)
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
with db() as conn:
|
||||
conn.execute(
|
||||
"UPDATE users SET breeder_status='pending' WHERE id=?",
|
||||
(user["id"],)
|
||||
)
|
||||
# Profil-Entwurf anlegen (oder überschreiben wenn rejected)
|
||||
conn.execute(
|
||||
"INSERT INTO breeder_profiles (user_id, zwingername, rasse_text, verein, vdh_mitglied, stadt, website, beschreibung) "
|
||||
"VALUES (?,?,?,?,?,?,?,?) "
|
||||
|
|
@ -135,10 +134,11 @@ async def breeder_apply(
|
|||
"verified_at=NULL",
|
||||
(user["id"], zwingername, rasse_text, verein, vdh_mitglied, stadt, website, beschreibung)
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO breeder_documents (user_id, dokument_typ, file_path) VALUES (?,?,?)",
|
||||
(user["id"], "antrag", filepath)
|
||||
)
|
||||
if filepath:
|
||||
conn.execute(
|
||||
"INSERT INTO breeder_documents (user_id, dokument_typ, file_path) VALUES (?,?,?)",
|
||||
(user["id"], "antrag", filepath)
|
||||
)
|
||||
|
||||
# Admin benachrichtigen
|
||||
admin_body = f"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue