54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
|
|
"""Default-Manual + Troubleshooting-Links pro Drucker-Modell.
|
||
|
|
|
||
|
|
Bambu-Wiki-URLs als Startpunkt — koennen pro konkretem Drucker in der
|
||
|
|
DB via drucker.manual_url / drucker.troubleshooting_url ueberschrieben
|
||
|
|
werden (Inline-Edit). Wenn Override gesetzt, gewinnt der.
|
||
|
|
"""
|
||
|
|
|
||
|
|
MODELL_LINKS = {
|
||
|
|
"P1S": {
|
||
|
|
"manual": "https://wiki.bambulab.com/en/p1",
|
||
|
|
"troubleshooting": "https://wiki.bambulab.com/en/p1/troubleshooting",
|
||
|
|
},
|
||
|
|
"X1C": {
|
||
|
|
"manual": "https://wiki.bambulab.com/en/x1",
|
||
|
|
"troubleshooting": "https://wiki.bambulab.com/en/x1/troubleshooting",
|
||
|
|
},
|
||
|
|
"P2S": {
|
||
|
|
"manual": "https://wiki.bambulab.com/de/p2s/manual/p2s-intro",
|
||
|
|
"troubleshooting": "https://wiki.bambulab.com/en/p2/troubleshooting",
|
||
|
|
},
|
||
|
|
"A1 mini": {
|
||
|
|
"manual": "https://wiki.bambulab.com/en/a1-mini",
|
||
|
|
"troubleshooting": "https://wiki.bambulab.com/en/a1-mini/troubleshooting",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def drucker_links(drucker):
|
||
|
|
"""Liefert (manual_url, troubleshooting_url) fuer einen Drucker.
|
||
|
|
|
||
|
|
Order of resolution: DB-Override > Modell-Default > None.
|
||
|
|
|
||
|
|
`drucker` darf ein sqlite3.Row oder dict sein — Hauptsache es hat
|
||
|
|
die Schluessel modell, manual_url, troubleshooting_url.
|
||
|
|
"""
|
||
|
|
modell = drucker["modell"] if drucker else None
|
||
|
|
default = MODELL_LINKS.get(modell, {})
|
||
|
|
return {
|
||
|
|
"manual": _trim(drucker, "manual_url") or default.get("manual"),
|
||
|
|
"troubleshooting": _trim(drucker, "troubleshooting_url") or default.get("troubleshooting"),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def _trim(drucker, schluessel):
|
||
|
|
"""Liest ein optionales Feld aus dem Row/Dict, gibt None wenn leer."""
|
||
|
|
try:
|
||
|
|
wert = drucker[schluessel]
|
||
|
|
except (KeyError, IndexError):
|
||
|
|
return None
|
||
|
|
if not wert:
|
||
|
|
return None
|
||
|
|
wert = wert.strip()
|
||
|
|
return wert or None
|