Add eSUN catalog, article lookup and account deletion
This commit is contained in:
1 parent
56f534f3ba
commit
c6da58060d
18 files changed
+3841
-36
No files matched your search
@@ -11,10 +11,12 @@ GITEA_TOKEN_PATH=./appdata/secrets/gitea_token
|
||||
FAM_BIND_IP=127.0.0.1
|
||||
FAM_PORT=8215
|
||||
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1
|
||||
# Bei Zugriff über einen HTTPS-Reverse-Proxy die externe Origin inklusive https:// eintragen.
|
||||
DJANGO_CSRF_TRUSTED_ORIGINS=
|
||||
# Lokales HTTP: 0. Für HTTPS im Betrieb auf 1 ändern!
|
||||
DJANGO_COOKIE_SECURE=0
|
||||
DJANGO_SECURE_SSL_REDIRECT=0
|
||||
# Nur einschalten, wenn ausschließlich der eigene Proxy das Backend erreicht und den Header setzt.
|
||||
DJANGO_TRUST_PROXY=0
|
||||
DJANGO_HSTS_SECONDS=0
|
||||
SEED_CATALOG=1
|
||||
@@ -22,7 +22,7 @@ Keine SPA, keine externen Schriften/Skripte, kein externer Datenbankserver.
|
||||
- Die Bestellhistorie zeigt die bestellten, eingetroffenen und übergebenen Positionen der Gruppe.
|
||||
Bestell- und Übergabezeitpunkte werden bei den jeweiligen Statuswechseln gespeichert.
|
||||
- Deaktivierte Varianten bleiben in vorhandenen Positionen sichtbar, sind nicht neu wählbar.
|
||||
- Einmalig ladbare Startkataloge für Bambu Lab und SUNLU sowie konsistentes
|
||||
- Einmalig ladbare Startkataloge für Bambu Lab, SUNLU und eSUN sowie konsistentes
|
||||
SQLite-Online-Backup.
|
||||
|
||||
Unter „Spule verbraucht“ lässt sich eine Rolle ausbuchen und dieselbe Variante optional in
|
||||
@@ -134,9 +134,12 @@ docker compose exec --user 99:100 app /app/runtime/venv/bin/python /app/runtime/
|
||||
|
||||
**Individuelles Passwort mit mindestens 12 Zeichen** wählen und erst am verdeckten Prompt tippen.
|
||||
Kein Standardpasswort, keine automatisch angelegten Benutzer. Passwortvalidierung nicht umgehen.
|
||||
Unter `/admin/` die weiteren normalen Konten mit jeweils eigenen Passwörtern anlegen. Deaktivieren
|
||||
statt Löschen erhält ihre Daten. Private Bestände, Drucker und Profilfelder sind nicht im Admin
|
||||
freigegeben; auch Administratoren erhalten dort keinen privaten Daten-Bypass.
|
||||
Unter `/admin/` die weiteren normalen Konten mit jeweils eigenen Passwörtern anlegen.
|
||||
Zum endgültigen Entfernen unter **Benutzer** das gewünschte Konto öffnen, **Löschen** wählen
|
||||
und bestätigen. Dabei werden auch dessen Bestand, Bestellwünsche samt Bestellhistorie,
|
||||
Drucker, Freigaben und gesendetes Feedback gelöscht. Beim Deaktivieren bleiben die Daten erhalten.
|
||||
Die Löschbestätigung zeigt die Anzahl der zugehörigen Datensätze. Private Bestände, Drucker
|
||||
und Profilfelder haben keine eigene Ansicht im Admin.
|
||||
|
||||
Bei abweichenden PUID/PGID stets dieselben numerischen IDs für Management-Befehle verwenden.
|
||||
`FAM_DATA_DIR=/data` muss auch im Container-ENV gesetzt sein, damit `docker exec` dieselbe DB nutzt.
|
||||
@@ -160,7 +163,7 @@ Alle Angaben sind Container-ENV; `.env.example` enthält die Compose-Variablenna
|
||||
| `DJANGO_SECURE_SSL_REDIRECT` | `0`, bei korrekt eingerichtetem HTTPS-Proxy `1` |
|
||||
| `DJANGO_TRUST_PROXY` | `0`, nur bei isoliertem vertrauenswürdigem Reverse Proxy `1` |
|
||||
| `DJANGO_HSTS_SECONDS` | `0`, erst nach verifiziertem HTTPS aktivieren |
|
||||
| `SEED_CATALOG` | Beispiel `1`: importiert die Startkataloge von Bambu Lab und SUNLU jeweils einmalig |
|
||||
| `SEED_CATALOG` | Beispiel `1`: importiert die Startkataloge von Bambu Lab, SUNLU und eSUN jeweils einmalig |
|
||||
|
||||
Compose-spezifisch: `FAM_IMAGE`, `FAM_APP_PATH`, `FAM_DATA_PATH`, `GITEA_TOKEN_PATH`,
|
||||
`FAM_BIND_IP` und `FAM_PORT`. Keine Secret-Werte, nur Einstellungen und Dateipfade.
|
||||
@@ -175,9 +178,28 @@ Optional `DJANGO_SECRET_KEY_FILE` mit einer für die Laufzeit-UID lesbaren Secre
|
||||
Nicht ungeschützt ins Internet veröffentlichen. Für produktive Zugriffe TLS und einen
|
||||
Login-Ratenbegrenzer am Reverse Proxy einrichten; **die App enthält keinen eigenen
|
||||
Brute-Force-Ratenbegrenzer**, auch nicht für `/admin/login/`.
|
||||
Bei `DJANGO_TRUST_PROXY=1` darf nur der vertrauenswürdige Proxy das Backend erreichen und muss
|
||||
fremde `X-Forwarded-Proto`-Header verwerfen/selbst setzen. Reines lokales HTTP ist ein
|
||||
Test-/LAN-Backend-Modus, keine Zusicherung für einen sicheren Internetbetrieb.
|
||||
Für Zugriff über einen eigenen HTTPS-Reverse-Proxy die folgenden Werte in der Compose-`.env`
|
||||
oder als Container-Variablen in Unraid setzen. `filament.example.org` durch den Hostnamen aus
|
||||
der Browseradresse ersetzen.
|
||||
|
||||
```dotenv
|
||||
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,filament.example.org
|
||||
DJANGO_CSRF_TRUSTED_ORIGINS=https://filament.example.org
|
||||
DJANGO_COOKIE_SECURE=1
|
||||
DJANGO_TRUST_PROXY=1
|
||||
```
|
||||
|
||||
`DJANGO_CSRF_TRUSTED_ORIGINS` erwartet die externe Adresse mit Schema und bei abweichendem
|
||||
Standardport inklusive Port, jeweils ohne Pfad oder abschließenden Schrägstrich.
|
||||
Der Proxy gibt den öffentlichen `Host` samt gegebenenfalls explizitem Port weiter
|
||||
und ersetzt `X-Forwarded-Proto` mit dem tatsächlichen Client-Protokoll. Bei
|
||||
`DJANGO_TRUST_PROXY=1` muss das Backend ausschließlich über den eigenen Proxy erreichbar sein.
|
||||
In Unraid die Änderung über **Docker → Fil-A-Management → Bearbeiten → Anwenden** übernehmen.
|
||||
Bei Compose den Container mit `docker compose up -d` neu erstellen lassen. Die Anmeldeseite
|
||||
anschließend über dieselbe externe HTTPS-Adresse frisch laden.
|
||||
|
||||
Falls die Anmeldung weiter mit 403 fehlschlägt, steht der konkrete Grund im App-Log hinter
|
||||
`Origin checking failed`, `Referer checking failed` oder `CSRF cookie not set`.
|
||||
`/healthz/` prüft SQLite und gibt nur `{"status":"ok"}` aus; für interne Tests keine HTTPS-Umleitung.
|
||||
|
||||
Alternativ zu HTTPS wird ein **separater lesender SSH-Deploy-Key** unterstützt:
|
||||
@@ -293,6 +315,11 @@ Farb-/Spulenkombinationen einschließlich technischer und Supportfilamente. Zube
|
||||
CMYK-Verkaufspaket sind keine einzeln auswählbaren Filamentvarianten und deshalb ausgenommen;
|
||||
dessen enthaltene PLA-Basic-Farben sind bereits einzeln vorhanden.
|
||||
|
||||
Ein eigener Einmal-Import ergänzt [PETG Basic](https://eu.store.bambulab.com/products/petg-basic)
|
||||
und [PETG Matte](https://eu.store.bambulab.com/products/petg-matte) auch in bestehenden
|
||||
Datenbanken. Die 42 zusätzlichen Varianten umfassen 21 Farben mit Spule und als Refill
|
||||
inklusive Artikelnummern, Herstellerfarbwerten und Produktbildern.
|
||||
|
||||
Der [deutsche SUNLU-Shop](https://de.store.sunlu.com/collections/3d-drucker-filament) liefert
|
||||
einen zweiten Startkatalog mit 67 Produkt-/Gewichtsausführungen und 561 Varianten aus dem
|
||||
öffentlichen Shopfeed vom 14. November 2026. Er enthält Spulen, Refill und größere
|
||||
@@ -301,6 +328,14 @@ dem Shopfeed. Wo SUNLU einen zuordenbaren Hexwert veröffentlicht, wird eine Far
|
||||
hinterlegt. Wenn das Angebot mehrere Rollengewichte unter derselben SKU führt, bleibt das
|
||||
einzelne Nettogewicht offen.
|
||||
|
||||
Der **eSUN-Startkatalog** enthält 50 Produkt-/Gewichtsausführungen und 438 bestätigte
|
||||
Farb-/Spulenkombinationen aus den [offiziellen Shopangeboten](https://eu.esun3dstore.com/),
|
||||
ergänzt um Einträge aus dem [eSUN-EU-Shop](https://esun3dstoreeu.com/).
|
||||
Stand ist der 14. November 2026. Enthalten sind einzelne Spulen und Refill mit 1,75 mm.
|
||||
Produktbilder und [Herstellerfarbwerte](https://www.esun3d.com/pla-pro-product) sind bei
|
||||
eindeutiger Zuordnung hinterlegt. Die Artikelnummern bleiben ohne verifizierbare Angabe frei
|
||||
und können im Admin ergänzt werden.
|
||||
|
||||
Die Datenstände werden mit dem Programm ausgeliefert und beim Start nicht aus dem Shop nachgeladen.
|
||||
Der erste erfolgreiche Import wird je Hersteller in der Datenbank markiert. Spätere Aufrufe überspringen
|
||||
den Import vollständig, sodass lokale Löschungen, Deaktivierungen, Umbenennungen und Ergänzungen
|
||||
|
||||
@@ -16,7 +16,9 @@ User 1 ── n Printer
|
||||
- Farbcode, Nettogewicht und Durchmesser sind optionale Varianteneigenschaften.
|
||||
- Bestand und Bestellwünsche sind getrennte Tabellen. Pro `(owner, variant)` existiert höchstens
|
||||
eine Position; Datenbank-Constraints begrenzen Mengen auf 1–9999.
|
||||
- Geschützte Katalog-Fremdschlüssel sowie das Deaktivieren statt Löschen erhalten Referenzen.
|
||||
- Geschützte Katalog-Fremdschlüssel und das Deaktivieren von Varianten erhalten Katalogreferenzen.
|
||||
- Beim bestätigten Löschen eines Kontos entfernt Django kaskadierend dessen Bestand, Bestellungen
|
||||
samt Historie, Drucker, Freigaben und Feedback.
|
||||
- Drucker gehören nur einer Person; Hersteller/Modell sind unabhängig vom Filamentkatalog.
|
||||
- Das Profil ist das bestehende Django-User-Modell, ohne öffentliche Profil-/ID-Route.
|
||||
In gemeinsamen Bestellwünschen erscheint ausschließlich der Benutzername, nicht Name/E-Mail.
|
||||
|
||||
+13
-1
@@ -24,6 +24,8 @@ class AccountAdmin(UserAdmin):
|
||||
search_fields = ("username",)
|
||||
ordering = ("username",)
|
||||
filter_horizontal = ()
|
||||
actions = None
|
||||
delete_confirmation_template = "admin/auth/user/delete_confirmation.html"
|
||||
|
||||
def lookup_allowed(self, lookup, value, request=None):
|
||||
# Django normally permits direct filters on all local model fields.
|
||||
@@ -35,7 +37,17 @@ class AccountAdmin(UserAdmin):
|
||||
} and super().lookup_allowed(lookup, value, request)
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False # Deactivate; preserve requests, ownership and private data.
|
||||
if obj is not None:
|
||||
if obj.pk == request.user.pk:
|
||||
return False
|
||||
if (obj.is_staff or obj.is_superuser) and not request.user.is_superuser:
|
||||
return False
|
||||
return super().has_delete_permission(request, obj)
|
||||
|
||||
def get_deleted_objects(self, objs, request):
|
||||
_, counts, perms_needed, protected = super().get_deleted_objects(objs, request)
|
||||
# Show counts without disclosing private stock and printer details.
|
||||
return [obj.get_username() for obj in objs], counts, perms_needed, protected
|
||||
|
||||
|
||||
@admin.register(Manufacturer, Color)
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
"""PETG Basic and PETG Matte from the current Bambu Lab EU store.
|
||||
|
||||
Color codes, spool options, net weights and images are from each product’s
|
||||
structured data. Swatches come from the hex code tables linked on those pages.
|
||||
Snapshot taken on 14 November 2026.
|
||||
"""
|
||||
|
||||
BAMBU_PETG_CATALOG = {
|
||||
"PETG Basic": (
|
||||
# https://eu.store.bambulab.com/products/petg-basic
|
||||
(
|
||||
"Orange",
|
||||
"refill",
|
||||
"30301",
|
||||
1000,
|
||||
"#FF671F",
|
||||
"https://store.bblcdn.eu/s8/default/2aec282c1ec545f880a7aa75fbec8f95/PETG_Basic_orange.jpg",
|
||||
),
|
||||
(
|
||||
"Orange",
|
||||
"spool",
|
||||
"30301",
|
||||
1000,
|
||||
"#FF671F",
|
||||
"https://store.bblcdn.eu/s8/default/2aec282c1ec545f880a7aa75fbec8f95/PETG_Basic_orange.jpg",
|
||||
),
|
||||
(
|
||||
"Red",
|
||||
"refill",
|
||||
"30201",
|
||||
1000,
|
||||
"#D6001C",
|
||||
"https://store.bblcdn.eu/s8/default/ff07f59007e94090af967488b25de3d3/RED.png",
|
||||
),
|
||||
(
|
||||
"Red",
|
||||
"spool",
|
||||
"30201",
|
||||
1000,
|
||||
"#D6001C",
|
||||
"https://store.bblcdn.eu/s8/default/ff07f59007e94090af967488b25de3d3/RED.png",
|
||||
),
|
||||
(
|
||||
"Yellow",
|
||||
"refill",
|
||||
"30402",
|
||||
1000,
|
||||
"#FCE300",
|
||||
"https://store.bblcdn.eu/s8/default/7fe9bf3f4d12489386370193fb02850c/YELLOW.png",
|
||||
),
|
||||
(
|
||||
"Yellow",
|
||||
"spool",
|
||||
"30402",
|
||||
1000,
|
||||
"#FCE300",
|
||||
"https://store.bblcdn.eu/s8/default/7fe9bf3f4d12489386370193fb02850c/YELLOW.png",
|
||||
),
|
||||
(
|
||||
"Green",
|
||||
"refill",
|
||||
"30502",
|
||||
1000,
|
||||
"#009639",
|
||||
"https://store.bblcdn.eu/s8/default/ccc39455d1fd4669ba583c3da3eff47b/Green_1.jpg",
|
||||
),
|
||||
(
|
||||
"Green",
|
||||
"spool",
|
||||
"30502",
|
||||
1000,
|
||||
"#009639",
|
||||
"https://store.bblcdn.eu/s8/default/ccc39455d1fd4669ba583c3da3eff47b/Green_1.jpg",
|
||||
),
|
||||
(
|
||||
"Navy Blue",
|
||||
"refill",
|
||||
"30604",
|
||||
1000,
|
||||
"#0086D6",
|
||||
"https://store.bblcdn.eu/s8/default/a3f70e8ec1ba4d90808e92edcf28f17d/Navy_Blue_1.jpg",
|
||||
),
|
||||
(
|
||||
"Navy Blue",
|
||||
"spool",
|
||||
"30604",
|
||||
1000,
|
||||
"#0086D6",
|
||||
"https://store.bblcdn.eu/s8/default/a3f70e8ec1ba4d90808e92edcf28f17d/Navy_Blue_1.jpg",
|
||||
),
|
||||
(
|
||||
"Reflex Blue",
|
||||
"refill",
|
||||
"30603",
|
||||
1000,
|
||||
"#001489",
|
||||
"https://store.bblcdn.eu/s8/default/9cad6210e4184cf28c1006b4a612c87f/REFLEX_BLUE.png",
|
||||
),
|
||||
(
|
||||
"Reflex Blue",
|
||||
"spool",
|
||||
"30603",
|
||||
1000,
|
||||
"#001489",
|
||||
"https://store.bblcdn.eu/s8/default/9cad6210e4184cf28c1006b4a612c87f/REFLEX_BLUE.png",
|
||||
),
|
||||
(
|
||||
"Dark Beige",
|
||||
"refill",
|
||||
"30403",
|
||||
1000,
|
||||
"#DBC8B6",
|
||||
"https://store.bblcdn.eu/s8/default/86f7a87158834e79813b43badc1b26af/Dark_Beige_1.jpg",
|
||||
),
|
||||
(
|
||||
"Dark Beige",
|
||||
"spool",
|
||||
"30403",
|
||||
1000,
|
||||
"#DBC8B6",
|
||||
"https://store.bblcdn.eu/s8/default/86f7a87158834e79813b43badc1b26af/Dark_Beige_1.jpg",
|
||||
),
|
||||
(
|
||||
"White",
|
||||
"refill",
|
||||
"30106",
|
||||
1000,
|
||||
"#FFFFFF",
|
||||
"https://store.bblcdn.eu/s8/default/523e094a800f4064bf5d93daa1d05a08/WHITE.png",
|
||||
),
|
||||
(
|
||||
"White",
|
||||
"spool",
|
||||
"30106",
|
||||
1000,
|
||||
"#FFFFFF",
|
||||
"https://store.bblcdn.eu/s8/default/523e094a800f4064bf5d93daa1d05a08/WHITE.png",
|
||||
),
|
||||
(
|
||||
"Black",
|
||||
"refill",
|
||||
"30105",
|
||||
1000,
|
||||
"#000000",
|
||||
"https://store.bblcdn.eu/s8/default/c5cd4b9fed76448d8611f956a92b0ea7/Black.png",
|
||||
),
|
||||
(
|
||||
"Black",
|
||||
"spool",
|
||||
"30105",
|
||||
1000,
|
||||
"#000000",
|
||||
"https://store.bblcdn.eu/s8/default/c5cd4b9fed76448d8611f956a92b0ea7/Black.png",
|
||||
),
|
||||
(
|
||||
"Dark Brown",
|
||||
"refill",
|
||||
"30800",
|
||||
1000,
|
||||
"#4F2C1D",
|
||||
"https://store.bblcdn.eu/s8/default/fcacc5422e634ae7975f57b970504c36/BARK_BROWN.png",
|
||||
),
|
||||
(
|
||||
"Dark Brown",
|
||||
"spool",
|
||||
"30800",
|
||||
1000,
|
||||
"#4F2C1D",
|
||||
"https://store.bblcdn.eu/s8/default/fcacc5422e634ae7975f57b970504c36/BARK_BROWN.png",
|
||||
),
|
||||
(
|
||||
"Gray",
|
||||
"refill",
|
||||
"30107",
|
||||
1000,
|
||||
"#7F7E83",
|
||||
"https://store.bblcdn.eu/s8/default/05d2eea2bf4d426faa7614da8069e354/GRAY.png",
|
||||
),
|
||||
(
|
||||
"Gray",
|
||||
"spool",
|
||||
"30107",
|
||||
1000,
|
||||
"#7F7E83",
|
||||
"https://store.bblcdn.eu/s8/default/05d2eea2bf4d426faa7614da8069e354/GRAY.png",
|
||||
),
|
||||
(
|
||||
"Misty Blue",
|
||||
"refill",
|
||||
"30108",
|
||||
1000,
|
||||
"#688197",
|
||||
"https://store.bblcdn.eu/s8/default/4825e2d206bd4e39bf7ef7c13bbdf20e/Misty_Blue_1.jpg",
|
||||
),
|
||||
(
|
||||
"Misty Blue",
|
||||
"spool",
|
||||
"30108",
|
||||
1000,
|
||||
"#688197",
|
||||
"https://store.bblcdn.eu/s8/default/4825e2d206bd4e39bf7ef7c13bbdf20e/Misty_Blue_1.jpg",
|
||||
),
|
||||
(
|
||||
"Pine Green",
|
||||
"refill",
|
||||
"30503",
|
||||
1000,
|
||||
"#034638",
|
||||
"https://store.bblcdn.eu/s8/default/d8a399750c884985b22f700e99623fa1/Pine_Green_1.jpg",
|
||||
),
|
||||
(
|
||||
"Pine Green",
|
||||
"spool",
|
||||
"30503",
|
||||
1000,
|
||||
"#034638",
|
||||
"https://store.bblcdn.eu/s8/default/d8a399750c884985b22f700e99623fa1/Pine_Green_1.jpg",
|
||||
),
|
||||
),
|
||||
"PETG Matte": (
|
||||
# https://eu.store.bambulab.com/products/petg-matte
|
||||
(
|
||||
"Black",
|
||||
"refill",
|
||||
"35101",
|
||||
1000,
|
||||
"#000000",
|
||||
"https://store.bblcdn.eu/s8/default/d70a3897529942a9b9ef310ee10112d0/black.png",
|
||||
),
|
||||
(
|
||||
"Black",
|
||||
"spool",
|
||||
"35101",
|
||||
1000,
|
||||
"#000000",
|
||||
"https://store.bblcdn.eu/s8/default/d70a3897529942a9b9ef310ee10112d0/black.png",
|
||||
),
|
||||
(
|
||||
"White",
|
||||
"refill",
|
||||
"35100",
|
||||
1000,
|
||||
"#FFFFFF",
|
||||
"https://store.bblcdn.eu/s8/default/7b8cfec40dc74d2585056b9c2406a7f7/07-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"White",
|
||||
"spool",
|
||||
"35100",
|
||||
1000,
|
||||
"#FFFFFF",
|
||||
"https://store.bblcdn.eu/s8/default/7b8cfec40dc74d2585056b9c2406a7f7/07-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Gray",
|
||||
"refill",
|
||||
"35102",
|
||||
1000,
|
||||
"#7F7E83",
|
||||
"https://store.bblcdn.eu/s8/default/2a77f7dfe46b4bdf957fd8115aadda0a/04-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Gray",
|
||||
"spool",
|
||||
"35102",
|
||||
1000,
|
||||
"#7F7E83",
|
||||
"https://store.bblcdn.eu/s8/default/2a77f7dfe46b4bdf957fd8115aadda0a/04-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Pink",
|
||||
"refill",
|
||||
"35700",
|
||||
1000,
|
||||
"#FABBCB",
|
||||
"https://store.bblcdn.eu/s8/default/20964b7502cb4623a32e4b4024aff384/02-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Pink",
|
||||
"spool",
|
||||
"35700",
|
||||
1000,
|
||||
"#FABBCB",
|
||||
"https://store.bblcdn.eu/s8/default/20964b7502cb4623a32e4b4024aff384/02-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Violet",
|
||||
"refill",
|
||||
"35702",
|
||||
1000,
|
||||
"#A7A4E0",
|
||||
"https://store.bblcdn.eu/s8/default/97bfea817df947498fa49a83ba3b44d7/08-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Violet",
|
||||
"spool",
|
||||
"35702",
|
||||
1000,
|
||||
"#A7A4E0",
|
||||
"https://store.bblcdn.eu/s8/default/97bfea817df947498fa49a83ba3b44d7/08-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Baby Blue",
|
||||
"refill",
|
||||
"35600",
|
||||
1000,
|
||||
"#B9D9EB",
|
||||
"https://store.bblcdn.eu/s8/default/502a01ccf9db42e4974cdbf748cb7a91/03-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Baby Blue",
|
||||
"spool",
|
||||
"35600",
|
||||
1000,
|
||||
"#B9D9EB",
|
||||
"https://store.bblcdn.eu/s8/default/502a01ccf9db42e4974cdbf748cb7a91/03-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Avocado Green",
|
||||
"refill",
|
||||
"35501",
|
||||
1000,
|
||||
"#BCE194",
|
||||
"https://store.bblcdn.eu/s8/default/f9d466844bea4f65ac3424ed245be52f/06-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Avocado Green",
|
||||
"spool",
|
||||
"35501",
|
||||
1000,
|
||||
"#BCE194",
|
||||
"https://store.bblcdn.eu/s8/default/f9d466844bea4f65ac3424ed245be52f/06-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Lime",
|
||||
"refill",
|
||||
"35500",
|
||||
1000,
|
||||
"#C0DF16",
|
||||
"https://store.bblcdn.eu/s8/default/54e6fd898f2c492d935e1acb2c18e8bc/05-compressed.jpg",
|
||||
),
|
||||
(
|
||||
"Lime",
|
||||
"spool",
|
||||
"35500",
|
||||
1000,
|
||||
"#C0DF16",
|
||||
"https://store.bblcdn.eu/s8/default/54e6fd898f2c492d935e1acb2c18e8bc/05-compressed.jpg",
|
||||
),
|
||||
),
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
+26
-2
@@ -47,6 +47,22 @@ class QuantityForm(forms.Form):
|
||||
quantity = forms.IntegerField(label="Stückzahl", min_value=1, max_value=9999)
|
||||
|
||||
|
||||
class ArticleLookupForm(forms.Form):
|
||||
article_number = forms.CharField(
|
||||
label="Artikelnummer",
|
||||
max_length=Variant._meta.get_field("manufacturer_color_code").max_length,
|
||||
error_messages={"required": "Bitte gib eine Artikelnummer ein."},
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"autocomplete": "off",
|
||||
"spellcheck": "false",
|
||||
"placeholder": "z. B. 40101",
|
||||
"data-article-number": "",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class ConsumeSpoolForm(forms.Form):
|
||||
quantity = forms.IntegerField(min_value=1, max_value=9999, widget=forms.HiddenInput)
|
||||
action = forms.ChoiceField(choices=[("consume", "Verbrauchen"), ("reorder", "Nachbestellen")])
|
||||
@@ -124,9 +140,17 @@ class VariantSelectionForm(forms.Form):
|
||||
.values_list("color_id", "swatch")
|
||||
)
|
||||
spools = set(narrowed.filter(color_id=color).values_list("spool_type", flat=True))
|
||||
self.fields["spool_type"].choices = [("", "Spulenausführung wählen")] + [
|
||||
(key, label) for key, label in Variant.SpoolType.choices if key in spools
|
||||
spool_choices = [
|
||||
(key, "Filament auf Spule" if key == Variant.SpoolType.SPOOL else label)
|
||||
for key, label in Variant.SpoolType.choices
|
||||
if key in spools
|
||||
]
|
||||
spool_field = self.fields["spool_type"]
|
||||
spool_field.choices = spool_choices
|
||||
if not spool_choices:
|
||||
spool_field.widget.attrs["disabled"] = True
|
||||
elif not self.is_bound and values.get("spool_type") not in spools:
|
||||
self.initial["spool_type"] = spool_choices[0][0]
|
||||
|
||||
def clean(self):
|
||||
cleaned = super().clean()
|
||||
|
||||
@@ -5,20 +5,30 @@ from django.db import transaction
|
||||
|
||||
from filament.bambu_catalog import BAMBU_LAB_CATALOG, BAMBU_LAB_VARIANT_COUNT
|
||||
from filament.bambu_images_0006 import bambu_image_url
|
||||
from filament.bambu_petg_catalog import BAMBU_PETG_CATALOG
|
||||
from filament.bambu_swatches_0005 import BAMBU_SWATCHES
|
||||
from filament.esun_catalog import ESUN_CATALOG
|
||||
from filament.models import CatalogBootstrap, Color, Manufacturer, ProductType, Variant
|
||||
from filament.sunlu_catalog import SUNLU_CATALOG, SUNLU_IMAGE_BASE
|
||||
|
||||
BAMBU_LAB_BOOTSTRAP_KEY = "bambu-lab-eu-initial-catalog"
|
||||
BAMBU_PETG_BOOTSTRAP_KEY = "bambu-lab-eu-petg-basic-matte"
|
||||
SUNLU_BOOTSTRAP_KEY = "sunlu-de-initial-catalog"
|
||||
ESUN_BOOTSTRAP_KEY = "esun-eu-initial-catalog"
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Importiert die Bambu-Lab- und SUNLU-Erstkataloge einmalig pro Datenbank."
|
||||
help = "Importiert die Erstkataloge von Bambu Lab, SUNLU und eSUN einmalig pro Datenbank."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.seed_bambu(options["verbosity"])
|
||||
self.seed_sunlu(options["verbosity"])
|
||||
self.seed_catalog(
|
||||
options["verbosity"], BAMBU_PETG_BOOTSTRAP_KEY, "Bambu Lab", BAMBU_PETG_CATALOG
|
||||
)
|
||||
self.seed_catalog(
|
||||
options["verbosity"], SUNLU_BOOTSTRAP_KEY, "SUNLU", SUNLU_CATALOG, sunlu_image_url
|
||||
)
|
||||
self.seed_catalog(options["verbosity"], ESUN_BOOTSTRAP_KEY, "eSUN", ESUN_CATALOG)
|
||||
|
||||
@transaction.atomic
|
||||
def seed_bambu(self, verbosity):
|
||||
@@ -65,14 +75,14 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def seed_sunlu(self, verbosity):
|
||||
_, should_import = CatalogBootstrap.objects.get_or_create(key=SUNLU_BOOTSTRAP_KEY)
|
||||
def seed_catalog(self, verbosity, key, manufacturer_name, catalog, image_url=None):
|
||||
_, should_import = CatalogBootstrap.objects.get_or_create(key=key)
|
||||
if not should_import:
|
||||
return
|
||||
|
||||
manufacturer, _ = Manufacturer.objects.get_or_create(name="SUNLU")
|
||||
manufacturer, _ = Manufacturer.objects.get_or_create(name=manufacturer_name)
|
||||
created = 0
|
||||
for name, catalog_variants in SUNLU_CATALOG.items():
|
||||
for name, catalog_variants in catalog.items():
|
||||
product, _ = ProductType.objects.get_or_create(manufacturer=manufacturer, name=name)
|
||||
for color_name, spool_type, sku, weight, swatch, image_path in catalog_variants:
|
||||
color, _ = Color.objects.get_or_create(name=color_name)
|
||||
@@ -85,13 +95,15 @@ class Command(BaseCommand):
|
||||
"net_weight_g": weight,
|
||||
"diameter_mm": Decimal("1.75"),
|
||||
"swatch": swatch,
|
||||
"image_url": SUNLU_IMAGE_BASE + image_path + "?width=144"
|
||||
if image_path
|
||||
else "",
|
||||
"image_url": image_url(image_path) if image_url else image_path,
|
||||
},
|
||||
)
|
||||
created += new
|
||||
if verbosity:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"SUNLU-Erstkatalog importiert: {created} Varianten ergänzt.")
|
||||
self.style.SUCCESS(f"{manufacturer_name}-Katalog: {created} Varianten ergänzt.")
|
||||
)
|
||||
|
||||
|
||||
def sunlu_image_url(path):
|
||||
return SUNLU_IMAGE_BASE + path + "?width=144" if path else ""
|
||||
@@ -19,6 +19,7 @@ class PrivatePageMiddleware:
|
||||
}:
|
||||
image_sources += (
|
||||
" https://cdn.shopify.com https://store.bblcdn.eu https://store.bblcdn.com"
|
||||
" https://ueeshop.ly200-cdn.com/u_file/UPBB/UPBB609/"
|
||||
)
|
||||
response["Content-Security-Policy"] = (
|
||||
"default-src 'self'; script-src 'self'; style-src 'self'; "
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.2.19 on 2026-11-14 15:05
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("filament", "0010_order_history_dates"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="variant",
|
||||
name="image_url",
|
||||
field=models.URLField(
|
||||
blank=True,
|
||||
help_text="HTTPS-Bildadresse aus dem CDN von Bambu Lab, SUNLU oder eSUN.",
|
||||
max_length=500,
|
||||
validators=[
|
||||
django.core.validators.RegexValidator(
|
||||
"\\Ahttps://(?:cdn\\.shopify\\.com/|store\\.bblcdn\\.eu/|store\\.bblcdn\\.com/|ueeshop\\.ly200-cdn\\.com/u_file/UPBB/UPBB609/)",
|
||||
"Bitte eine HTTPS-Bildadresse von einer unterstützten CDN-Domain eingeben.",
|
||||
)
|
||||
],
|
||||
verbose_name="Produktbild",
|
||||
),
|
||||
),
|
||||
]
|
||||
+3
-2
@@ -90,11 +90,12 @@ class Variant(models.Model):
|
||||
blank=True,
|
||||
validators=[
|
||||
RegexValidator(
|
||||
r"\Ahttps://(?:cdn\.shopify\.com|store\.bblcdn\.eu|store\.bblcdn\.com)/",
|
||||
r"\Ahttps://(?:cdn\.shopify\.com/|store\.bblcdn\.eu/|store\.bblcdn\.com/"
|
||||
r"|ueeshop\.ly200-cdn\.com/u_file/UPBB/UPBB609/)",
|
||||
"Bitte eine HTTPS-Bildadresse von einer unterstützten CDN-Domain eingeben.",
|
||||
)
|
||||
],
|
||||
help_text="Bildadresse von cdn.shopify.com, store.bblcdn.eu oder store.bblcdn.com.",
|
||||
help_text="HTTPS-Bildadresse aus dem CDN von Bambu Lab, SUNLU oder eSUN.",
|
||||
)
|
||||
net_weight_g = models.PositiveIntegerField(
|
||||
"Nettogewicht (g)", null=True, blank=True, validators=[MinValueValidator(1)]
|
||||
|
||||
@@ -549,6 +549,16 @@ td.quantity {
|
||||
.variant-panel {
|
||||
overflow: visible;
|
||||
}
|
||||
.article-lookup {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.article-lookup > :is(input, select) {
|
||||
flex: 1 1 230px;
|
||||
min-width: 0;
|
||||
}
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
|
||||
@@ -143,7 +143,12 @@ function enhanceColorSelect(select) {
|
||||
|
||||
const form = document.querySelector("[data-catalog-form]");
|
||||
if (form) {
|
||||
const selects = [...form.querySelectorAll("select")];
|
||||
form.querySelector("[data-article-number]").addEventListener("keydown", (event) => {
|
||||
if (event.key !== "Enter" || event.isComposing) return;
|
||||
event.preventDefault();
|
||||
form.requestSubmit(form.querySelector("[data-article-lookup]"));
|
||||
});
|
||||
const selects = [...form.querySelectorAll(".form-grid select")];
|
||||
selects.forEach((select, index) => {
|
||||
select.addEventListener("change", () => {
|
||||
selects.slice(index + 1).forEach((next) => {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import secrets
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import Client
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.test import Client, override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from filament.models import InventoryItem, Printer
|
||||
from filament.models import Feedback, InventoryItem, OrderItem, Printer, SharingPreferences, Variant
|
||||
|
||||
from .base import CatalogTestCase
|
||||
|
||||
@@ -40,6 +42,68 @@ class AdminAuthenticationTests(CatalogTestCase):
|
||||
user.refresh_from_db()
|
||||
self.assertFalse(user.is_active)
|
||||
|
||||
def test_admin_can_delete_account_and_its_data_after_confirmation(self):
|
||||
self.client.force_login(self.admin)
|
||||
InventoryItem.objects.create(owner=self.alice, variant=self.spool, quantity=7)
|
||||
OrderItem.objects.create(owner=self.alice, variant=self.spool, quantity=1)
|
||||
OrderItem.objects.create(
|
||||
owner=self.alice, variant=self.spool, quantity=2, status=OrderItem.Status.HANDED_OVER
|
||||
)
|
||||
Printer.objects.create(
|
||||
owner=self.alice, manufacturer="Privates Druckermodell", model="Test"
|
||||
)
|
||||
SharingPreferences.objects.create(
|
||||
owner=self.alice, share_inventory=True, share_printers=True
|
||||
)
|
||||
Feedback.objects.create(sender=self.alice, message="Nachricht zur Löschprüfung")
|
||||
other_stock = InventoryItem.objects.create(owner=self.bob, variant=self.spool, quantity=3)
|
||||
other_order = OrderItem.objects.create(owner=self.bob, variant=self.spool, quantity=4)
|
||||
|
||||
url = reverse("admin:auth_user_delete", args=[self.alice.pk])
|
||||
self.assertContains(self.client.get(f"/admin/auth/user/{self.alice.pk}/change/"), url)
|
||||
confirmation = self.client.get(url)
|
||||
self.assertContains(confirmation, "Bestellwünsche samt Bestellhistorie")
|
||||
self.assertNotContains(confirmation, "Privates Druckermodell")
|
||||
self.assertNotContains(confirmation, "7 ×")
|
||||
self.assertNotContains(confirmation, "Nachricht zur Löschprüfung")
|
||||
self.assertTrue(get_user_model().objects.filter(pk=self.alice.pk).exists())
|
||||
self.assertEqual(OrderItem.objects.filter(owner=self.alice).count(), 2)
|
||||
|
||||
csrf_client = Client(enforce_csrf_checks=True)
|
||||
csrf_client.force_login(self.admin)
|
||||
self.assertEqual(csrf_client.post(url, {"post": "yes"}).status_code, 403)
|
||||
csrf_client.get(url)
|
||||
self.assertRedirects(
|
||||
csrf_client.post(
|
||||
url,
|
||||
{"post": "yes", "csrfmiddlewaretoken": csrf_client.cookies["csrftoken"].value},
|
||||
),
|
||||
reverse("admin:auth_user_changelist"),
|
||||
)
|
||||
self.assertFalse(get_user_model().objects.filter(pk=self.alice.pk).exists())
|
||||
self.assertFalse(InventoryItem.objects.filter(owner=self.alice).exists())
|
||||
self.assertFalse(OrderItem.objects.filter(owner=self.alice).exists())
|
||||
self.assertFalse(Printer.objects.filter(owner=self.alice).exists())
|
||||
self.assertFalse(SharingPreferences.objects.filter(owner=self.alice).exists())
|
||||
self.assertFalse(Feedback.objects.filter(sender=self.alice).exists())
|
||||
self.assertTrue(InventoryItem.objects.filter(pk=other_stock.pk).exists())
|
||||
self.assertTrue(OrderItem.objects.filter(pk=other_order.pk).exists())
|
||||
self.assertTrue(Variant.objects.filter(pk=self.spool.pk).exists())
|
||||
|
||||
def test_delete_requires_permission_and_keeps_the_current_admin_account(self):
|
||||
self.client.force_login(self.admin)
|
||||
admin_delete_url = reverse("admin:auth_user_delete", args=[self.admin.pk])
|
||||
self.assertEqual(self.client.post(admin_delete_url, {"post": "yes"}).status_code, 403)
|
||||
self.bob.is_staff = True
|
||||
self.bob.save(update_fields=["is_staff"])
|
||||
self.client.force_login(self.bob)
|
||||
member_delete_url = reverse("admin:auth_user_delete", args=[self.alice.pk])
|
||||
self.assertEqual(self.client.post(member_delete_url, {"post": "yes"}).status_code, 403)
|
||||
self.bob.user_permissions.add(Permission.objects.get(codename="delete_user"))
|
||||
self.assertEqual(self.client.post(admin_delete_url, {"post": "yes"}).status_code, 403)
|
||||
self.assertTrue(get_user_model().objects.filter(pk=self.admin.pk).exists())
|
||||
self.assertTrue(get_user_model().objects.filter(pk=self.alice.pk).exists())
|
||||
|
||||
def test_admin_can_deactivate_catalog_variant_without_deleting_positions(self):
|
||||
self.client.force_login(self.admin)
|
||||
InventoryItem.objects.create(owner=self.alice, variant=self.spool, quantity=2)
|
||||
@@ -126,3 +190,37 @@ class AdminAuthenticationTests(CatalogTestCase):
|
||||
self.assertEqual(self.client.get("/abmelden/").status_code, 405)
|
||||
self.client.post("/abmelden/")
|
||||
self.assertEqual(self.client.get("/bestand/").status_code, 302)
|
||||
|
||||
@override_settings(
|
||||
ALLOWED_HOSTS=["filament.example.org", "app.internal"],
|
||||
SECURE_PROXY_SSL_HEADER=("HTTP_X_FORWARDED_PROTO", "https"),
|
||||
CSRF_TRUSTED_ORIGINS=["https://filament.example.org"],
|
||||
CSRF_COOKIE_SECURE=True,
|
||||
SESSION_COOKIE_SECURE=True,
|
||||
)
|
||||
def test_csrf_protected_login_behind_https_reverse_proxy(self):
|
||||
client = Client(enforce_csrf_checks=True)
|
||||
headers = {"host": "filament.example.org", "x-forwarded-proto": "https"}
|
||||
response = client.get("/anmelden/", headers=headers)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTrue(response.wsgi_request.is_secure())
|
||||
self.assertTrue(response.cookies["csrftoken"]["secure"])
|
||||
credentials = {"username": self.alice.username, "password": self.password}
|
||||
payload = credentials | {"csrfmiddlewaretoken": client.cookies["csrftoken"].value}
|
||||
origin = {"origin": "https://filament.example.org"}
|
||||
self.assertEqual(
|
||||
client.post("/anmelden/", credentials, headers=headers | origin).status_code, 403
|
||||
)
|
||||
self.assertEqual(
|
||||
client.post(
|
||||
"/anmelden/", payload, headers=headers | {"origin": "https://other.example.org"}
|
||||
).status_code,
|
||||
403,
|
||||
)
|
||||
# The explicitly trusted origin also covers proxies that rewrite Host.
|
||||
response = client.post(
|
||||
"/anmelden/", payload, headers=headers | {"host": "app.internal"} | origin
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertTrue(response.cookies["sessionid"]["secure"])
|
||||
self.assertEqual(client.get("/bestand/", headers=headers).status_code, 200)
|
||||
@@ -2,7 +2,12 @@ from django.core.management import call_command, get_commands
|
||||
|
||||
from filament.bambu_catalog import BAMBU_LAB_PRODUCT_COUNT, BAMBU_LAB_VARIANT_COUNT
|
||||
from filament.forms import VariantSelectionForm
|
||||
from filament.management.commands.seed_catalog import BAMBU_LAB_BOOTSTRAP_KEY, SUNLU_BOOTSTRAP_KEY
|
||||
from filament.management.commands.seed_catalog import (
|
||||
BAMBU_LAB_BOOTSTRAP_KEY,
|
||||
BAMBU_PETG_BOOTSTRAP_KEY,
|
||||
ESUN_BOOTSTRAP_KEY,
|
||||
SUNLU_BOOTSTRAP_KEY,
|
||||
)
|
||||
from filament.models import (
|
||||
CatalogBootstrap,
|
||||
Color,
|
||||
@@ -71,7 +76,10 @@ class CatalogTests(CatalogTestCase):
|
||||
form = VariantSelectionForm(selection=self.selection())
|
||||
self.assertEqual(list(form.fields["product_type"].queryset), [self.product])
|
||||
self.assertEqual(set(form.fields["color"].queryset), {self.red, self.black})
|
||||
self.assertEqual({s for s, _ in form.fields["spool_type"].choices}, {"", "spool", "refill"})
|
||||
self.assertEqual(
|
||||
form.fields["spool_type"].choices,
|
||||
[("spool", "Filament auf Spule"), ("refill", "Refill (ohne Spule)")],
|
||||
)
|
||||
invalid = self.selection() | {"product_type": other_product.pk, "color": other_color.pk}
|
||||
self.assertFalse(VariantSelectionForm(invalid).is_valid())
|
||||
response = self.client.post("/bestand/hinzufuegen/", invalid)
|
||||
@@ -108,6 +116,75 @@ class CatalogTests(CatalogTestCase):
|
||||
self.assertContains(response, "formnovalidate")
|
||||
self.assertFalse(InventoryItem.objects.exists())
|
||||
|
||||
def test_spool_choices_have_no_placeholder_and_keep_the_existing_selection(self):
|
||||
for url in ("/bestand/hinzufuegen/", "/bestellung/hinzufuegen/"):
|
||||
for variant in (self.spool, self.refill, self.black_spool):
|
||||
with self.subTest(url=url, variant=variant):
|
||||
response = self.client.post(url, self.selection(variant) | {"action": "filter"})
|
||||
self.assertNotContains(response, "Spulenausführung wählen")
|
||||
self.assertContains(response, "Filament auf Spule")
|
||||
field = response.context["form"]["spool_type"]
|
||||
self.assertEqual(field.value(), variant.spool_type)
|
||||
self.assertEqual(
|
||||
"refill" in dict(field.field.choices), variant.color_id == self.red.pk
|
||||
)
|
||||
data = self.selection(self.black_spool) | {"spool_type": "", "action": "filter"}
|
||||
self.assertEqual(
|
||||
self.client.post(url, data).context["form"]["spool_type"].value(), "spool"
|
||||
)
|
||||
|
||||
def test_article_lookup_prefills_both_forms_and_preserves_quantity(self):
|
||||
self.refill.manufacturer_color_code = "PLA-RD-01"
|
||||
self.refill.save(update_fields=["manufacturer_color_code"])
|
||||
for path, model in (("bestand", InventoryItem), ("bestellung", OrderItem)):
|
||||
with self.subTest(path=path):
|
||||
url = f"/{path}/hinzufuegen/"
|
||||
response = self.client.post(
|
||||
url, {"action": "lookup", "article_number": " pla-rd-01 ", "quantity": 4}
|
||||
)
|
||||
self.assertContains(response, "Variante suchen")
|
||||
self.assertEqual(response.context["form"].initial, self.selection(self.refill, "4"))
|
||||
self.assertFalse(model.objects.exists())
|
||||
self.assertRedirects(
|
||||
self.client.post(url, response.context["form"].initial), f"/{path}/"
|
||||
)
|
||||
self.assertEqual(model.objects.get(variant=self.refill).quantity, 4)
|
||||
|
||||
def test_article_lookup_requires_a_choice_for_duplicate_active_codes(self):
|
||||
Variant.objects.filter(pk__in=[self.spool.pk, self.refill.pk]).update(
|
||||
manufacturer_color_code="10100"
|
||||
)
|
||||
self.black_spool.manufacturer_color_code = "10100"
|
||||
self.black_spool.is_active = False
|
||||
self.black_spool.save()
|
||||
url = "/bestand/hinzufuegen/"
|
||||
lookup = {"article_number": "10100", "quantity": 2}
|
||||
response = self.client.post(url, lookup | {"action": "lookup"})
|
||||
self.assertContains(response, "Mehrere Varianten gefunden")
|
||||
self.assertEqual(set(response.context["matches"]), {self.spool, self.refill})
|
||||
self.assertNotIn("spool_type", response.context["form"].initial)
|
||||
|
||||
invalid = self.client.post(
|
||||
url, lookup | {"action": "pick", "article_variant": self.black_spool.pk}
|
||||
)
|
||||
self.assertContains(invalid, "Bitte wähle eine der gefundenen Varianten.")
|
||||
picked = self.client.post(
|
||||
url, lookup | {"action": "pick", "article_variant": self.spool.pk}
|
||||
)
|
||||
self.assertEqual(picked.context["form"].initial, self.selection(self.spool, "2"))
|
||||
self.assertFalse(InventoryItem.objects.exists())
|
||||
|
||||
def test_article_lookup_ignores_partial_and_unknown_codes(self):
|
||||
self.spool.manufacturer_color_code = "40101"
|
||||
self.spool.save(update_fields=["manufacturer_color_code"])
|
||||
url = "/bestellung/hinzufuegen/"
|
||||
response = self.client.post(
|
||||
url, self.selection() | {"action": "lookup", "article_number": "4010"}
|
||||
)
|
||||
self.assertContains(response, "Zu dieser Artikelnummer gibt es keinen aktiven Eintrag.")
|
||||
self.assertEqual(response.context["form"]["color"].value(), str(self.red.pk))
|
||||
self.assertFalse(OrderItem.objects.exists())
|
||||
|
||||
def test_color_preview_is_available_in_both_flows_and_remains_optional(self):
|
||||
self.spool.swatch = "#DE4343"
|
||||
self.spool.save(update_fields=["swatch"])
|
||||
@@ -152,10 +229,10 @@ class CatalogTests(CatalogTestCase):
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
self.assertEqual(
|
||||
ProductType.objects.filter(manufacturer__name="Bambu Lab").count(),
|
||||
BAMBU_LAB_PRODUCT_COUNT,
|
||||
BAMBU_LAB_PRODUCT_COUNT + 2,
|
||||
)
|
||||
bambu_variants = Variant.objects.filter(product_type__manufacturer__name="Bambu Lab")
|
||||
self.assertEqual(bambu_variants.count(), BAMBU_LAB_VARIANT_COUNT)
|
||||
self.assertEqual(bambu_variants.count(), BAMBU_LAB_VARIANT_COUNT + 42)
|
||||
self.assertFalse(
|
||||
bambu_variants.exclude(pk__in=(self.spool.pk, self.refill.pk, self.black_spool.pk))
|
||||
.filter(image_url="")
|
||||
@@ -191,6 +268,13 @@ class CatalogTests(CatalogTestCase):
|
||||
).swatch,
|
||||
"#000000,#A34342",
|
||||
)
|
||||
response = self.client.post(
|
||||
"/bestand/hinzufuegen/", {"action": "lookup", "article_number": "40101"}
|
||||
)
|
||||
self.assertEqual(
|
||||
{(variant.color.name, variant.spool_type) for variant in response.context["matches"]},
|
||||
{("ABS Black", "spool"), ("ABS Black", "refill")},
|
||||
)
|
||||
count = Variant.objects.count()
|
||||
inactive = Variant.objects.filter(manufacturer_color_code="11100").first()
|
||||
removed = Variant.objects.get(
|
||||
@@ -219,7 +303,12 @@ class CatalogTests(CatalogTestCase):
|
||||
variants = Variant.objects.filter(product_type__manufacturer=sunlu)
|
||||
self.assertEqual(variants.count(), 561)
|
||||
self.assertEqual(ProductType.objects.filter(manufacturer=sunlu).count(), 67)
|
||||
self.assertEqual(Variant.objects.filter(product_type__manufacturer=self.maker).count(), 3)
|
||||
self.assertEqual(
|
||||
Variant.objects.filter(product_type__manufacturer=self.maker)
|
||||
.exclude(product_type__name__in=("PETG Basic", "PETG Matte"))
|
||||
.count(),
|
||||
3,
|
||||
)
|
||||
self.assertTrue(CatalogBootstrap.objects.filter(key=SUNLU_BOOTSTRAP_KEY).exists())
|
||||
|
||||
pla = variants.filter(product_type__name="PLA", color__name="Schwarz")
|
||||
@@ -248,3 +337,82 @@ class CatalogTests(CatalogTestCase):
|
||||
self.assertFalse(variants.filter(product_type__name="PETG-CF10").exists())
|
||||
refill.refresh_from_db()
|
||||
self.assertFalse(refill.is_active)
|
||||
|
||||
def test_esun_imports_once_into_existing_installations(self):
|
||||
CatalogBootstrap.objects.create(key=BAMBU_LAB_BOOTSTRAP_KEY)
|
||||
CatalogBootstrap.objects.create(key=SUNLU_BOOTSTRAP_KEY)
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
esun = Manufacturer.objects.get(name="eSUN")
|
||||
variants = Variant.objects.filter(product_type__manufacturer=esun)
|
||||
self.assertEqual(variants.count(), 438)
|
||||
self.assertEqual(ProductType.objects.filter(manufacturer=esun).count(), 50)
|
||||
self.assertTrue(CatalogBootstrap.objects.filter(key=ESUN_BOOTSTRAP_KEY).exists())
|
||||
|
||||
pla_black = variants.filter(product_type__name="PLA Plus", color__name="Black")
|
||||
self.assertEqual(set(pla_black.values_list("spool_type", flat=True)), {"spool", "refill"})
|
||||
refill = pla_black.get(spool_type="refill")
|
||||
self.assertEqual(refill.swatch, "#272729")
|
||||
self.assertEqual(refill.net_weight_g, 1000)
|
||||
self.assertTrue(refill.image_url.startswith("https://ueeshop.ly200-cdn.com/"))
|
||||
refill.full_clean()
|
||||
for path in ("bestand", "bestellung"):
|
||||
self.assertRedirects(
|
||||
self.client.post(f"/{path}/hinzufuegen/", self.selection(refill)), f"/{path}/"
|
||||
)
|
||||
response = self.client.get(f"/{path}/")
|
||||
self.assertContains(response, f'src="{refill.image_url}"')
|
||||
self.assertIn(
|
||||
"https://ueeshop.ly200-cdn.com/u_file/UPBB/UPBB609/",
|
||||
response["Content-Security-Policy"],
|
||||
)
|
||||
refill.is_active = False
|
||||
refill.manufacturer_color_code = "CUSTOM-001"
|
||||
refill.save(update_fields=["is_active", "manufacturer_color_code"])
|
||||
pla_black.get(spool_type="spool").delete()
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
refill.refresh_from_db()
|
||||
self.assertFalse(refill.is_active)
|
||||
self.assertEqual(refill.manufacturer_color_code, "CUSTOM-001")
|
||||
self.assertEqual(variants.count(), 437)
|
||||
self.assertEqual(pla_black.count(), 1)
|
||||
|
||||
def test_bambu_petg_expands_an_existing_catalog_once(self):
|
||||
CatalogBootstrap.objects.bulk_create(
|
||||
[
|
||||
CatalogBootstrap(key=key)
|
||||
for key in (BAMBU_LAB_BOOTSTRAP_KEY, SUNLU_BOOTSTRAP_KEY, ESUN_BOOTSTRAP_KEY)
|
||||
]
|
||||
)
|
||||
product = ProductType.objects.create(manufacturer=self.maker, name="PETG Basic")
|
||||
white, _ = Color.objects.get_or_create(name="White")
|
||||
edited = Variant.objects.create(
|
||||
product_type=product,
|
||||
color=white,
|
||||
spool_type="spool",
|
||||
manufacturer_color_code="CUSTOM-WHITE",
|
||||
is_active=False,
|
||||
)
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
variants = Variant.objects.filter(product_type__manufacturer=self.maker).exclude(
|
||||
product_type=self.product
|
||||
)
|
||||
self.assertEqual(variants.filter(product_type__name="PETG Basic").count(), 26)
|
||||
self.assertEqual(variants.filter(product_type__name="PETG Matte").count(), 16)
|
||||
self.assertTrue(CatalogBootstrap.objects.filter(key=BAMBU_PETG_BOOTSTRAP_KEY).exists())
|
||||
self.assertFalse(variants.filter(product_type__name="PETG HF").exists())
|
||||
edited.refresh_from_db()
|
||||
self.assertFalse(edited.is_active)
|
||||
self.assertEqual(edited.manufacturer_color_code, "CUSTOM-WHITE")
|
||||
|
||||
refill = variants.get(manufacturer_color_code="30106", spool_type="refill")
|
||||
self.assertEqual(refill.swatch, "#FFFFFF")
|
||||
self.assertEqual(refill.net_weight_g, 1000)
|
||||
self.assertTrue(refill.image_url.startswith("https://store.bblcdn.eu/"))
|
||||
form = VariantSelectionForm(selection=self.selection(refill))
|
||||
self.assertEqual(
|
||||
set(form.fields["product_type"].queryset.values_list("name", flat=True)),
|
||||
{"PETG Basic", "PETG Matte"},
|
||||
)
|
||||
refill.delete()
|
||||
call_command("seed_catalog", verbosity=0)
|
||||
self.assertFalse(variants.filter(manufacturer_color_code="30106").exists())
|
||||
+44
-3
@@ -12,6 +12,7 @@ from django.urls import reverse
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
from .forms import (
|
||||
ArticleLookupForm,
|
||||
ConsumeSpoolForm,
|
||||
FeedbackForm,
|
||||
OrderStatusForm,
|
||||
@@ -20,6 +21,7 @@ from .forms import (
|
||||
QuantityForm,
|
||||
SharingPreferencesForm,
|
||||
VariantSelectionForm,
|
||||
selection_id,
|
||||
)
|
||||
from .models import InventoryItem, OrderItem, Printer, SharingPreferences, Variant
|
||||
from .services import add_quantity, consume_spool, update_order_status
|
||||
@@ -282,10 +284,42 @@ def inventory_add(request):
|
||||
|
||||
|
||||
def _add_position(request, model, back, title, destination):
|
||||
is_add = request.method == "POST" and request.POST.get("action") != "filter"
|
||||
selection = request.POST if request.method == "POST" else request.GET
|
||||
action = request.POST.get("action")
|
||||
is_add = request.method == "POST" and action not in {"filter", "lookup", "pick"}
|
||||
lookup = ArticleLookupForm(request.POST if action in {"lookup", "pick"} else None)
|
||||
matches = []
|
||||
if lookup.is_bound and lookup.is_valid():
|
||||
matches = list(
|
||||
Variant.objects.filter(
|
||||
is_active=True,
|
||||
manufacturer_color_code__iexact=lookup.cleaned_data["article_number"],
|
||||
).select_related("product_type__manufacturer", "color")
|
||||
)
|
||||
if not matches:
|
||||
lookup.add_error(
|
||||
"article_number", "Zu dieser Artikelnummer gibt es keinen aktiven Eintrag."
|
||||
)
|
||||
else:
|
||||
match = matches[0] if len(matches) == 1 else None
|
||||
if action == "pick":
|
||||
picked = selection_id(request.POST.get("article_variant"))
|
||||
match = next((variant for variant in matches if variant.pk == picked), None)
|
||||
if match is None:
|
||||
lookup.add_error("article_number", "Bitte wähle eine der gefundenen Varianten.")
|
||||
if match is not None:
|
||||
selection = {
|
||||
"manufacturer": match.manufacturer.pk,
|
||||
"material": match.product_type.material_and_subtype[0],
|
||||
"product_type": match.product_type_id,
|
||||
"color": match.color_id,
|
||||
"spool_type": match.spool_type,
|
||||
"quantity": selection.get("quantity", 1),
|
||||
}
|
||||
matches = []
|
||||
form = VariantSelectionForm(
|
||||
request.POST if is_add else None,
|
||||
selection=request.POST if request.method == "POST" else request.GET,
|
||||
selection=selection,
|
||||
)
|
||||
if is_add and form.is_valid():
|
||||
try:
|
||||
@@ -300,7 +334,14 @@ def _add_position(request, model, back, title, destination):
|
||||
return render(
|
||||
request,
|
||||
"filament/select_variant.html",
|
||||
{"form": form, "title": title, "back_name": back, "destination": destination},
|
||||
{
|
||||
"form": form,
|
||||
"lookup": lookup,
|
||||
"matches": matches,
|
||||
"title": title,
|
||||
"back_name": back,
|
||||
"destination": destination,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{% extends "admin/delete_confirmation.html" %}
|
||||
|
||||
{% block delete_confirm %}
|
||||
<p>Mit dem Konto werden auch dessen Filamentbestand, Bestellwünsche samt Bestellhistorie, Drucker, Freigaben und gesendetes Feedback dauerhaft gelöscht.</p>
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,28 @@
|
||||
{% extends "base.html" %}{% block title %}{{ title }} · Fil-A-Management{% endblock %}{% block content %}
|
||||
<a class="back-link" href="{% url back_name %}">← Zurück</a><div class="page-heading"><div><p class="eyebrow">AUS DEM GEMEINSAMEN KATALOG</p><h1>{{ title }}</h1><p class="muted">Wähle Schritt für Schritt eine Variante für {{ destination }}.</p></div></div>
|
||||
<a class="back-link" href="{% url back_name %}">← Zurück</a><div class="page-heading"><div><p class="eyebrow">AUS DEM GEMEINSAMEN KATALOG</p><h1>{{ title }}</h1><p class="muted">Wähle eine Variante für {{ destination }} oder suche nach ihrer Artikelnummer.</p></div></div>
|
||||
<section class="panel form-panel variant-panel"><form method="post" data-catalog-form>{% csrf_token %}{{ form.non_field_errors }}
|
||||
<div class="field">
|
||||
{{ lookup.article_number.label_tag }}
|
||||
<div class="article-lookup">
|
||||
{{ lookup.article_number }}
|
||||
<button class="button secondary" type="submit" name="action" value="lookup" formnovalidate data-article-lookup>Variante suchen</button>
|
||||
</div>
|
||||
{{ lookup.article_number.errors }}
|
||||
</div>
|
||||
{% if matches %}
|
||||
<div class="field">
|
||||
<label for="article-variant">Mehrere Varianten gefunden</label>
|
||||
<div class="article-lookup">
|
||||
<select id="article-variant" name="article_variant">
|
||||
<option value="">Variante auswählen</option>
|
||||
{% for variant in matches %}
|
||||
<option value="{{ variant.pk }}">{{ variant }}{% if variant.net_weight_g %} · {{ variant.net_weight_g }} g{% endif %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button class="button secondary" type="submit" name="action" value="pick" formnovalidate>Auswahl übernehmen</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-grid">{% for field in form %}<div class="field">{{ field.label_tag }}{{ field }}{{ field.errors }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}</div>{% endfor %}</div>
|
||||
<p class="hint">Jede Auswahl grenzt die folgenden Optionen ein. Nur aktive, angelegte Varianten sind wählbar.</p>
|
||||
<div class="form-actions">
|
||||
|
||||
Reference in new issue
Block a user