Vier zusammenhaengende Iterationen, die das Funktions-Geruest der AG aufbauen.
Alle 6 Migrationen sind idempotent und legen Schema-Erweiterungen + initiale
Seeds an (Mock-Projekte nur, falls Profil 100 existiert — auf prod nicht).
Software-Sektion (Etappe 3):
- software_seite-Tabelle: schlanker Karten-Katalog (slug, titel, urls,
plattform, kategorie, sortierung, Cover-BLOB)
- 7 Initial-Karten (Bambu Studio/Handy, Printables, MakerWorld,
TinkerCAD, Onshape, Gridfinity-Generator)
- Admin-Verwaltung: Liste, Anlegen-Form, Bearbeiten, Aktiv-Toggle,
Hart-Loeschen, Bild-Upload via Crop-Tool (Strg+V/Drag&Drop, 400x400)
Drucker-Verwaltung (Etappe 5-vorgezogen):
- drucker.freigegeben + gesperrt_grund (Lehrer-Sperre fuer Reparatur)
- drucker.manual_url + troubleshooting_url (Override fuer Modell-Defaults)
- SuS-View /drucker (eingeloggt): Kacheln + Sperre-Banner + Belegung
- Admin /admin/drucker: Status-Override (idle/printing/failed/...),
Sperren/Freigeben mit Grund, Inline-Edit fuer URLs
Slot-System / Reservierung (Etappe 7-vorgezogen):
- profil.reservieren_freigeschaltet (Lehrer schaltet manuell frei,
ersetzt L1-Gate-Automatismus)
- services/slots.py: Konflikt-Check, Belegungs-Helper
- SuS-Routen /cockpit/slot/neu (mit Konflikt-Check), /cockpit/slots,
Stornieren
- Admin /admin/slots Uebersicht + /admin/slot/neu (Lehrer reserviert
fuer SuS) + Hart-Loeschen + Profil-Freigabe-Toggle
Selbstlern-Loop (Etappe 6 — Kern):
- projekt-Spalten: 3-Achsen-Eval (Gesamt + Planung + Ausfuehrung),
was_klappte_nicht, cover_blob, modellier_software_slug,
drucker_id_used, makerworld_url
- Regel: max. 1 aktives Projekt pro SuS, neues nur nach Freigabe
(auto bei zufrieden/mittel, Lehrer-Review bei gelernt)
- SuS-Werkstatt-Sektion: Titel + Beschreibung + Software-Dropdown +
Drucker-Dropdown + MakerWorld-URL + Files-Upload (drag&drop,
base64, max 30 MB)
- Cover-Bild via Crop-Tool (Re-use admin_software_bild-Pattern)
- Abschluss-Block: Pflicht Cover + mindestens 1 Datei
- Eval-Form: visuelle 3x3 Radio-Karten + 2 Freitexte
- Lehrer-Review: /admin/projekte mit Filter (wartet/in_arbeit/
abgeschlossen/rueckfrage), Aktionen freigeben/rueckfrage/loeschen
- Oeffentlicher Katalog /projekte: Sortier-Tabelle (Titel/Person/
Status/Erfolg/Datum), aufklappbare Detail mit Cover/Beschreibung/
Datei-Downloads/MakerWorld-Link
- Wiederhol-Logik: "Sowas mache ich auch" via Verknuepfung
(vorlage_projekt_id), bidirektionale Lineage-Banner
Cockpit-Refactoring:
- Projekt-Karte ganz oben (vor Onboarding) mit "Hier weitermachen"
- Check-In-Quick-Actions: nach Auswahl direkt zu /cockpit/projekt/neu,
/drucker, /lektionen, /cockpit/projekt/<aktiv>
- "Modus aendern"-Button im Eingecheckt-Banner
- Admin-Dashboard-Hub mit Karten: SuS-Profile, Software, Lektionen,
Drucker, Reservierungen, Projekte (Badge bei wartenden), Alph
Bug-Fixes:
- Admin-Login redirected jetzt auf /admin/dashboard statt /admin/profile
- app.py: neue Jinja-Filter iso_format + dauer_min
- .gitignore: .claude/ ausschliessen (lokale launch.json)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
229 lines
7.9 KiB
Python
229 lines
7.9 KiB
Python
"""Reine Status-Helper fuer das progressive Cockpit (V1).
|
|
|
|
Trennt Daten-Logik vom HTTP-Layer: die Funktionen hier bekommen eine
|
|
profil_id und liefern dicts/listen, die das Template direkt verwendet.
|
|
|
|
So bleibt routes/profil.py kurz und das Cockpit-Verhalten ist isoliert
|
|
testbar.
|
|
"""
|
|
from datetime import date, datetime, timedelta
|
|
from typing import Optional
|
|
|
|
from database import get_db
|
|
|
|
ONBOARDING_LEKTIONEN = [1, 2, 3] # Pflicht fuer Neue, siehe E-013
|
|
ONBOARDING_L1 = 1 # Schaltet Slot-Buchung frei (V2)
|
|
|
|
|
|
def get_onboarding_fortschritt(profil_id: int) -> dict:
|
|
"""Liefert pro Onboarding-Lektion den Status.
|
|
|
|
Returns:
|
|
{
|
|
'lektionen': [
|
|
{'nummer': 1, 'titel': 'Drucker-Kennenlernen + Sicherheit',
|
|
'status': 'fertig'|'laeuft'|'offen', 'aktuell': True/False},
|
|
...
|
|
],
|
|
'alle_fertig': bool,
|
|
'l1_fertig': bool, # V2: schaltet Slot-Buchung frei
|
|
'naechste': dict | None, # naechste offene/laufende Lektion (Sprung-Vorschlag)
|
|
}
|
|
"""
|
|
conn = get_db()
|
|
rows = conn.execute(
|
|
"SELECT l.nummer, l.titel, COALESCE(s.status, 'offen') AS status "
|
|
"FROM lektion l "
|
|
"LEFT JOIN profil_lektion_status s "
|
|
" ON s.lektion_nummer = l.nummer AND s.profil_id = ? "
|
|
"WHERE l.onboarding = 1 AND l.aktiv = 1 "
|
|
"ORDER BY l.nummer",
|
|
(profil_id,)
|
|
).fetchall()
|
|
conn.close()
|
|
|
|
lektionen = [dict(r) for r in rows]
|
|
alle_fertig = all(l["status"] == "fertig" for l in lektionen) and len(lektionen) > 0
|
|
l1_fertig = any(l["nummer"] == ONBOARDING_L1 and l["status"] == "fertig" for l in lektionen)
|
|
|
|
# naechste: erste, die nicht fertig ist
|
|
naechste = next((l for l in lektionen if l["status"] != "fertig"), None)
|
|
for l in lektionen:
|
|
l["aktuell"] = (naechste is not None and l["nummer"] == naechste["nummer"])
|
|
|
|
return {
|
|
"lektionen": lektionen,
|
|
"alle_fertig": alle_fertig,
|
|
"l1_fertig": l1_fertig,
|
|
"naechste": naechste,
|
|
}
|
|
|
|
|
|
def get_check_in_heute(profil_id: int) -> Optional[dict]:
|
|
"""Liefert den Check-In von heute (oder None, wenn noch keiner)."""
|
|
conn = get_db()
|
|
row = conn.execute(
|
|
"SELECT id, modus, freitext, erstellt_am FROM check_in "
|
|
"WHERE profil_id = ? AND besuch_datum = ?",
|
|
(profil_id, date.today().isoformat())
|
|
).fetchone()
|
|
conn.close()
|
|
return dict(row) if row else None
|
|
|
|
|
|
def get_offene_rueckfragen(profil_id: int) -> list[dict]:
|
|
"""Rueckfragen zu eigenen Projekten, die noch offen sind (V6-Banner)."""
|
|
conn = get_db()
|
|
rows = conn.execute(
|
|
"SELECT r.id, r.text, r.erstellt_am, p.titel AS projekt_titel, p.id AS projekt_id "
|
|
"FROM projekt_rueckfrage r "
|
|
"JOIN projekt p ON p.id = r.projekt_id "
|
|
"WHERE p.profil_id = ? AND r.status = 'offen' "
|
|
"ORDER BY r.erstellt_am DESC",
|
|
(profil_id,)
|
|
).fetchall()
|
|
conn.close()
|
|
return [dict(r) for r in rows]
|
|
|
|
|
|
def get_ungelesene_notizen(profil_id: int) -> list[dict]:
|
|
"""Lehrer-Notizen, die noch nicht gelesen wurden."""
|
|
conn = get_db()
|
|
rows = conn.execute(
|
|
"SELECT id, text, typ, erstellt_am FROM lehrer_notiz "
|
|
"WHERE profil_id = ? AND gelesen_am IS NULL "
|
|
"ORDER BY erstellt_am DESC",
|
|
(profil_id,)
|
|
).fetchall()
|
|
conn.close()
|
|
return [dict(r) for r in rows]
|
|
|
|
|
|
def get_aktive_projekte(profil_id: int) -> list[dict]:
|
|
"""Eigene Projekte mit status_lebenszyklus='in_arbeit'.
|
|
|
|
Nach Etappe 6: max. 1 (Regel "ein aktives Projekt pro SuS").
|
|
Liefert trotzdem Liste, damit das Template unveraendert bleibt.
|
|
"""
|
|
conn = get_db()
|
|
rows = conn.execute(
|
|
"SELECT id, titel, beschreibung_md, geaendert_am, "
|
|
" (cover_blob IS NOT NULL) AS hat_cover "
|
|
"FROM projekt "
|
|
"WHERE profil_id = ? AND status_lebenszyklus = 'in_arbeit' "
|
|
"ORDER BY geaendert_am DESC",
|
|
(profil_id,)
|
|
).fetchall()
|
|
conn.close()
|
|
return [dict(r) for r in rows]
|
|
|
|
|
|
def get_projekt_kontext(profil_id: int) -> dict:
|
|
"""Liefert den Projekt-Kontext fuers Cockpit:
|
|
- aktives (in_arbeit)
|
|
- darf_neues + sperr_grund
|
|
- letztes_abgeschlossenes (wenn Wartet auf Freigabe oder Rueckfrage: anzeigen)
|
|
"""
|
|
from services.projekte import darf_neues_anlegen, aktives_projekt, letztes_projekt
|
|
conn = get_db()
|
|
aktiv = aktives_projekt(conn, profil_id)
|
|
darf, grund = darf_neues_anlegen(conn, profil_id)
|
|
letztes = letztes_projekt(conn, profil_id) if not aktiv else None
|
|
conn.close()
|
|
return {
|
|
"aktiv": dict(aktiv) if aktiv else None,
|
|
"darf_neues": darf,
|
|
"sperr_grund": grund,
|
|
"letztes": dict(letztes) if letztes else None,
|
|
}
|
|
|
|
|
|
def get_paarung(profil_id: int) -> Optional[dict]:
|
|
"""Aktive Paarung des SuS (oder None)."""
|
|
conn = get_db()
|
|
row = conn.execute(
|
|
"SELECT pa.id AS paarung_id, "
|
|
" CASE WHEN pa.profil_a = ? THEN pa.profil_b ELSE pa.profil_a END AS partner_id, "
|
|
" pa.gebildet_am "
|
|
"FROM paarung pa "
|
|
"WHERE pa.aktiv = 1 AND (pa.profil_a = ? OR pa.profil_b = ?)",
|
|
(profil_id, profil_id, profil_id)
|
|
).fetchone()
|
|
if not row:
|
|
conn.close()
|
|
return None
|
|
partner = conn.execute(
|
|
"SELECT id, vorname, tier FROM profil WHERE id = ?",
|
|
(row["partner_id"],)
|
|
).fetchone()
|
|
conn.close()
|
|
return {
|
|
"paarung_id": row["paarung_id"],
|
|
"partner": dict(partner) if partner else None,
|
|
"gebildet_am": row["gebildet_am"],
|
|
}
|
|
|
|
|
|
def get_offene_anfragen_an_mich(profil_id: int) -> list[dict]:
|
|
"""Paarungs-Anfragen, die jemand an mich gestellt hat (Status 'wartet')."""
|
|
conn = get_db()
|
|
# Tabelle existiert evtl. noch nicht, wenn diese Funktion vor _ensure_anfrage_tabelle aufgerufen wird
|
|
try:
|
|
rows = conn.execute(
|
|
"SELECT a.id, a.erstellt_am, p.id AS von_id, p.vorname AS von_vorname, p.tier AS von_tier "
|
|
"FROM profil_anfrage a "
|
|
"JOIN profil p ON p.id = a.von_profil_id "
|
|
"WHERE a.an_profil_id = ? AND a.status = 'wartet' "
|
|
"ORDER BY a.erstellt_am DESC",
|
|
(profil_id,)
|
|
).fetchall()
|
|
except Exception:
|
|
rows = []
|
|
conn.close()
|
|
return [dict(r) for r in rows]
|
|
|
|
|
|
def get_andere_profile(profil_id: int) -> list[dict]:
|
|
"""Andere aktive Profile in derselben AG (fuer Paarungs-Anfrage)."""
|
|
conn = get_db()
|
|
rows = conn.execute(
|
|
"SELECT id, vorname, tier "
|
|
"FROM profil "
|
|
"WHERE aktiv = 1 AND id != ? AND ag_id = ("
|
|
" SELECT ag_id FROM profil WHERE id = ?"
|
|
") "
|
|
"ORDER BY vorname COLLATE NOCASE",
|
|
(profil_id, profil_id)
|
|
).fetchall()
|
|
conn.close()
|
|
return [dict(r) for r in rows]
|
|
|
|
|
|
# ===========================================================================
|
|
# Cockpit-Status-Bundle: ein dict mit allem, was das Cockpit-Template braucht
|
|
# ===========================================================================
|
|
|
|
def get_cockpit_status(profil_id: int) -> dict:
|
|
"""Bundle aller Daten fuer das progressive Cockpit (V1).
|
|
|
|
Das Template entscheidet anhand dieses dicts, welche Karten gezeigt werden.
|
|
"""
|
|
onb = get_onboarding_fortschritt(profil_id)
|
|
aktive_projekte = get_aktive_projekte(profil_id)
|
|
projekt_kontext = get_projekt_kontext(profil_id)
|
|
paarung = get_paarung(profil_id)
|
|
return {
|
|
"onboarding": onb,
|
|
"check_in_heute": get_check_in_heute(profil_id),
|
|
"rueckfragen": get_offene_rueckfragen(profil_id),
|
|
"notizen": get_ungelesene_notizen(profil_id),
|
|
"aktive_projekte": aktive_projekte,
|
|
"projekt": projekt_kontext, # neu: Selbstlern-Loop-Kontext
|
|
"paarung": paarung,
|
|
"offene_anfragen": get_offene_anfragen_an_mich(profil_id),
|
|
# Progressive-Schalter:
|
|
"ist_neu": not onb["alle_fertig"],
|
|
"darf_slots_buchen": onb["l1_fertig"],
|
|
"hat_projekte": len(aktive_projekte) > 0,
|
|
}
|