Add filament previews, article numbers and admin feedback
This commit is contained in:
1 parent
7b56a0e3ef
commit
40d6843147
23 files changed
+1334
-17
No files matched your search
@@ -16,6 +16,7 @@ urlpatterns = [
|
||||
),
|
||||
path("abmelden/", auth_views.LogoutView.as_view(), name="logout"),
|
||||
path("katalog/", views.catalog, name="catalog"),
|
||||
path("feedback/", views.feedback, name="feedback"),
|
||||
path("profil/", views.profile, name="profile"),
|
||||
path(
|
||||
"profil/passwort/",
|
||||
|
||||
@@ -37,8 +37,9 @@ keine Verschlüsselung gegen den Betreiber.
|
||||
Templates rendern alle Seiten serverseitig. Das kleine JavaScript sendet bei einer Auswahl nur
|
||||
den Filter-POST ab; der Server berechnet die zulässigen Folgeoptionen und prüft die endgültige
|
||||
Kombination erneut. Ohne JS funktioniert dieselbe Kaskade mit dem Aktualisieren-Button.
|
||||
Dynamische Seiten erhalten `Cache-Control: private, no-store`; die eigentliche App eine CSP
|
||||
nur für eigene Ressourcen. Django-Admin nutzt seine eigenen Sicherheitsmechanismen.
|
||||
Dynamische Seiten erhalten `Cache-Control: private, no-store`. Die CSP erlaubt auf Bestands-
|
||||
und Bestelllisten zusätzlich Produktbilder von den hinterlegten Shop-CDNs. Der Browser lädt sie
|
||||
direkt ohne Referrer. Django-Admin nutzt seine eigenen Sicherheitsmechanismen.
|
||||
|
||||
## SQLite und Laufzeit
|
||||
|
||||
|
||||
+23
-2
@@ -1,12 +1,13 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.utils.text import Truncator
|
||||
|
||||
from .models import Color, Manufacturer, ProductType, Variant
|
||||
from .models import Color, Feedback, Manufacturer, ProductType, Variant
|
||||
|
||||
admin.site.site_header = "Fil-A-Management · Administration"
|
||||
admin.site.site_title = "Fil-A-Management"
|
||||
admin.site.index_title = "Konten und gemeinsamer Katalog"
|
||||
admin.site.index_title = "Konten, Katalog und Feedback"
|
||||
admin.site.unregister(User)
|
||||
admin.site.unregister(Group)
|
||||
|
||||
@@ -67,3 +68,23 @@ class VariantAdmin(admin.ModelAdmin):
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False # Catalog history stays addressable: deactivate instead.
|
||||
|
||||
|
||||
@admin.register(Feedback)
|
||||
class FeedbackAdmin(admin.ModelAdmin):
|
||||
list_display = ("preview", "sender", "created_at")
|
||||
list_display_links = ("preview",)
|
||||
list_select_related = ("sender",)
|
||||
search_fields = ("message", "sender__username")
|
||||
readonly_fields = ("sender", "created_at", "message")
|
||||
view_on_site = False
|
||||
|
||||
@admin.display(description="Nachricht")
|
||||
def preview(self, obj):
|
||||
return Truncator(obj.message).chars(85)
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
@@ -0,0 +1,392 @@
|
||||
"""Official Bambu Lab EU variant images for migration 0006 and the starter catalog.
|
||||
|
||||
Source: https://bambulab-eu.myshopify.com/collections/bambu-lab-3d-printer-filament
|
||||
The shop often uses the same photo for spool and refill.
|
||||
Keep this snapshot stable for reproducible migrations.
|
||||
"""
|
||||
|
||||
SHOPIFY_IMAGES = "https://cdn.shopify.com/s/files/1/0645/5876/0155/"
|
||||
|
||||
# Product, manufacturer color code (or color name if there is no code).
|
||||
IMAGE_PATHS = {
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13612",
|
||||
): "files/teal_4dc29df4-13e2-4c00-9e6a-7dbf9183952a.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13611",
|
||||
): "files/000878ce6144c05ffac949f66b05a18b_0a1f2a15-2a6c-4e9e-88b1-029f32d29e27.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13710",
|
||||
): "files/996c0314d3c9f4f6a92e228ed4c8e264_a6207c48-38ce-4034-8302-449a67d23b51.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13301",
|
||||
): "files/c8682a1b6d56a22c3b0a59f59bf75cf5_b6dcbcfa-e6f8-41b9-a666-bef24ba52ac7.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13210",
|
||||
): "files/520f764beb1954cab793b251ed2a5a3f.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13510",
|
||||
): "files/e250fdbcaf7669fa3269b6565491cdcc.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13410",
|
||||
): "files/af0454a2a27b7c6259624f48c64717dd.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13211",
|
||||
): "files/b250b32bdc6d015ef107c6c2880ac956.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13610",
|
||||
): "files/cce64cbc630f968803ae0beb0146a780.jpg?v=1745483755&width=144",
|
||||
(
|
||||
"PLA Translucent",
|
||||
"13711",
|
||||
): "files/bc1c912b64c066d06fd795fee51d877b.jpg?v=1745483755&width=144",
|
||||
("PLA Basic", "10100"): "files/White.jpg?v=1736242873&width=144",
|
||||
("PLA Basic", "10201"): "files/Beige.jpg?v=1736242873&width=144",
|
||||
("PLA Basic", "10104"): "files/plalightgray.jpg?v=1736242873&width=144",
|
||||
("PLA Basic", "10400"): "files/Yellow.jpg?v=1736242873&width=144",
|
||||
("PLA Basic", "10402"): "files/SunflowerYellow.jpg?v=1736242873&width=144",
|
||||
("PLA Basic", "10401"): "files/Gold.jpg?v=1738745357&width=144",
|
||||
("PLA Basic", "10301"): "files/PumpkinOrange.jpg?v=1738745357&width=144",
|
||||
("PLA Basic", "10300"): "files/Orange.jpg?v=1738745357&width=144",
|
||||
("PLA Basic", "10503"): "files/BrightGreen.jpg?v=1736242932&width=144",
|
||||
("PLA Basic", "10501"): "files/Bambu_Green.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10502"): "files/2df013fd41a034aa180c1c5f641ef9c4.png?v=1737095626&width=144",
|
||||
("PLA Basic", "10203"): "files/Pink.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10204"): "files/HotPink.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10202"): "files/Magenta.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10200"): "files/Red.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10205"): "files/MaroonRed.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10700"): "files/PLAPurple.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10701"): "files/IndigoPurple.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10605"): "files/Turquoise.jpg?v=1737095626&width=144",
|
||||
(
|
||||
"PLA Basic",
|
||||
"10603",
|
||||
): "files/CMYK-Cyan-1_e332b67e-db4e-4f11-b05e-196bcf7dcad7.png?v=1737095626&width=144",
|
||||
("PLA Basic", "10604"): "files/CobaltBlue.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10601"): "files/PLABasicBlue.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10800"): "products/PLA-Basic_Brown.png?v=1737095626&width=144",
|
||||
("PLA Basic", "10802"): "files/CocoaBrown.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10801"): "files/Bronze.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10103"): "products/PLA-Basic_Gray.png?v=1737095626&width=144",
|
||||
("PLA Basic", "10102"): "files/Sliver.jpg?v=1737095626&width=144",
|
||||
("PLA Basic", "10602"): "products/PLA-Basic_Blue-Gray.png?v=1737095626&width=144",
|
||||
("PLA Basic", "10105"): "files/pladarkgray.jpg?v=1737095626&width=144",
|
||||
(
|
||||
"PLA Basic",
|
||||
"10101",
|
||||
): "products/PLA-Basic_Black_29c482c8-ccd6-4559-bf2b-058f7d0d798f.png?v=1737095626&width=144",
|
||||
("PLA Matte", "11100"): "products/PLA-Matte_Ivory-White.png?v=1710931478&width=144",
|
||||
("PLA Matte", "11800"): "products/PLA-Matte_Latte-Brown.png?v=1717494869&width=144",
|
||||
("PLA Matte", "11102"): "products/PLA-Matte_Ash-Gray.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11401"): "files/PLAMattedeserttan2.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11400"): "products/PLA-Matte_Yellow.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11300"): "products/PLA-Matte_Mandarine-Orange.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11201"): "products/PLA-Matte_Sakura-Pink.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11500"): "products/PLA-Matte_Grass-Green.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11601"): "products/PLA-Matte_Ice-Blue.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11600"): "products/PLA-Matte_Marine-Blue.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11700"): "products/PLA-Matte_Lilac-Purple.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11200"): "products/PLA-Matte_Scarlet-Red.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11202"): "files/plamattedark_1.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11801"): "files/plamattedark_4.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11501"): "files/plamattedark_2.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11602"): "files/plamattedark_3.png?v=1717491277&width=144",
|
||||
("PLA Matte", "11101"): "products/PLA-Matte_Charcoal.png?v=1717491277&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11103",
|
||||
): "files/7_890c24b1-12ea-47e1-908a-c8c8afb2b48c.jpg?v=1738815754&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11204",
|
||||
): "files/6_f72c2422-d7b7-4097-94a8-5d03ca276299.jpg?v=1738815754&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11603",
|
||||
): "files/4_98e0178d-1490-4ba4-81fb-a696a6a5714a.jpg?v=1738815754&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11502",
|
||||
): "files/2_29663f78-0df7-4382-b6e7-01fc2bacf724.jpg?v=1738815754&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11802",
|
||||
): "files/3_aa1c9150-6090-4d99-80eb-94e08e1f0838.jpg?v=1738815754&width=144",
|
||||
("PLA Matte", "11803"): "files/8.jpg?v=1738815754&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11203",
|
||||
): "files/5_3f98d7f9-1567-41c1-93eb-af106f8c77a0.jpg?v=1738815754&width=144",
|
||||
(
|
||||
"PLA Matte",
|
||||
"11104",
|
||||
): "files/1_ea5b7083-7377-4995-bef2-6c066be034b2.jpg?v=1738815736&width=144",
|
||||
("PLA Silk+", "13108"): "files/cf2723db072c4371b3606938b8cccdb9.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13206"): "files/PLA_Silk_10.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13603"): "files/PLA_Silk_7.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13404"): "files/PLA_Silk_3.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13507"): "files/PLA_Silk_2.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13205"): "files/PLA_Silk_5.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13506"): "files/PLA_Silk_12.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13604"): "files/PLA_Silk_4.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13702"): "files/PLA_Silk_9.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13207"): "files/PLA_Silk_1.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13110"): "files/PLA_Silk_6.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13109"): "files/PLA_Silk_11.jpg?v=1742804031&width=144",
|
||||
("PLA Silk+", "13405"): "files/PLA_Silk_8.jpg?v=1742804031&width=144",
|
||||
("PETG HF", "33200"): "files/5_87e53b22-3a47-4e93-adce-7f40106815c0.jpg?v=1721201484&width=144",
|
||||
("PETG HF", "33600"): "files/PETG_HF_5.jpg?v=1721201478&width=144",
|
||||
("PETG HF", "33102"): "files/PETG_HF_6.jpg?v=1721201479&width=144",
|
||||
("PETG HF", "33100"): "files/PETG_HF_7.jpg?v=1721201479&width=144",
|
||||
("PETG HF", "33101"): "files/PETG_HF_1.jpg?v=1721201479&width=144",
|
||||
("PETG HF", "33400"): "files/PETG_HF_2.jpg?v=1721201478&width=144",
|
||||
("PETG HF", "33300"): "files/PETG_HF_4.jpg?v=1721201479&width=144",
|
||||
("PETG HF", "33500"): "files/PETG_HF_3.jpg?v=1721201478&width=144",
|
||||
("PETG HF", "33502"): "files/PETGHFNEWCOLOR_6.jpg?v=1728360455&width=144",
|
||||
("PETG HF", "33801"): "files/PETGHFNEWCOLOR_1.jpg?v=1728360454&width=144",
|
||||
("PETG HF", "33103"): "files/PETGHFNEWCOLOR_3.jpg?v=1728360454&width=144",
|
||||
("PETG HF", "33401"): "files/PETGHFNEWCOLOR_5.jpg?v=1728360455&width=144",
|
||||
("PETG HF", "33501"): "files/PETGHFNEWCOLOR_4.jpg?v=1728360454&width=144",
|
||||
("PETG HF", "33601"): "files/PETGHFNEWCOLOR_2.jpg?v=1728360454&width=144",
|
||||
(
|
||||
"PETG Translucent",
|
||||
"32501",
|
||||
): "files/JP34951_dfb10fec-368d-47a7-8bd8-bb506498a9bd.jpg?v=1705040347&width=144",
|
||||
("PETG Translucent", "32600"): "files/JP34971.jpg?v=1705040347&width=144",
|
||||
(
|
||||
"PETG Translucent",
|
||||
"32101",
|
||||
): "files/3d4408c8738e6ed420e7e514a97a8bf9.png?v=1714027739&width=144",
|
||||
("PETG Translucent", "32200"): "files/JP34961.jpg?v=1705040347&width=144",
|
||||
("PETG Translucent", "32500"): "files/JP34954.jpg?v=1705040347&width=144",
|
||||
("PETG Translucent", "32300"): "files/JP34975.jpg?v=1705040347&width=144",
|
||||
("PETG Translucent", "32700"): "files/JP34969.jpg?v=1705040347&width=144",
|
||||
("PETG Translucent", "32800"): "files/JP34965.jpg?v=1705040347&width=144",
|
||||
("PETG Translucent", "32100"): "files/JP34968.jpg?v=1705040347&width=144",
|
||||
("ABS", "40102"): "files/ABSsilver.png?v=1735869590&width=144",
|
||||
("ABS", "40101"): "products/ABS_Black.png?v=1735869590&width=144",
|
||||
("ABS", "40100"): "products/ABS_White.png?v=1735869590&width=144",
|
||||
("ABS", "40200"): "products/ABS_Red.png?v=1735869590&width=144",
|
||||
("ABS", "40500"): "files/ABSbambugreen.png?v=1735869590&width=144",
|
||||
("ABS", "40300"): "files/ABSorange.png?v=1735869590&width=144",
|
||||
("ABS", "40602"): "files/0be9a584b30358020d8706f2aa8ec9c2.jpg?v=1735869563&width=144",
|
||||
("ABS", "40402"): "files/7376d19b161f2a93a4051e47289d0505.jpg?v=1735869563&width=144",
|
||||
("ABS", "40600"): "products/ABS_Blue.png?v=1735869563&width=144",
|
||||
("ABS", "40502"): "files/80cf6768c03d129dfa6a01ac67a5b402.jpg?v=1735869563&width=144",
|
||||
("ABS", "40601"): "files/000878ce6144c05ffac949f66b05a18b.jpg?v=1735869563&width=144",
|
||||
("Support for PLA (New Version)", "65104"): "files/Support3.png?v=1742785118&width=144",
|
||||
("TPU 90A", "51900"): "files/TPU_90_Frozen.jpg?v=1741081938&width=144",
|
||||
("TPU 90A", "51901"): "files/TPU_90_Blaze.jpg?v=1742913692&width=144",
|
||||
("TPU 90A", "51103"): "files/TPU_90_BK.png?v=1742913692&width=144",
|
||||
("TPU 90A", "51105"): "files/TPU_90_White.jpg?v=1742913692&width=144",
|
||||
("TPU 85A", "51500"): "files/TPU_85_Cyan.jpg?v=1742913692&width=144",
|
||||
("TPU 85A", "51305"): "files/TPU_85_Orange.jpg?v=1742913692&width=144",
|
||||
(
|
||||
"PLA Silk Dual Color",
|
||||
"Velvet Eclipse (Black-Red)",
|
||||
): "files/Silk_Dual_Color_Black-red.jpg?v=1741235156&width=144",
|
||||
(
|
||||
"PLA Silk Dual Color",
|
||||
"Neon City (Blue-Magenta)",
|
||||
): "files/neoncity.png?v=1741235156&width=144",
|
||||
(
|
||||
"PLA Silk Dual Color",
|
||||
"Midnight Blaze (Blue-Red)",
|
||||
): "files/midnightblaze2.png?v=1741234974&width=144",
|
||||
(
|
||||
"PLA Silk Dual Color",
|
||||
"Gilded Rose (Pink-Gold)",
|
||||
): "files/glidedrose.png?v=1741234974&width=144",
|
||||
(
|
||||
"PLA Silk Dual Color",
|
||||
"Blue Hawaii (Blue-Green)",
|
||||
): "files/blueHawaii.png?v=1741234974&width=144",
|
||||
("PLA Basic Gradient", "10907"): "files/pink_blue.jpg?v=1745376970&width=144",
|
||||
("PLA Basic Gradient", "10905"): "files/bluebuble.jpg?v=1745376970&width=144",
|
||||
("PLA Basic Gradient", "10903"): "files/pink_gradient.jpg?v=1745376970&width=144",
|
||||
("PLA Basic Gradient", "10904"): "files/gradient_green.jpg?v=1745376970&width=144",
|
||||
("PLA Basic Gradient", "10906"): "files/sunset_orange.jpg?v=1745376970&width=144",
|
||||
("PLA Basic Gradient", "10902"): "files/A00-M2-1.75-1000-spl.png?v=1745376970&width=144",
|
||||
(
|
||||
"PLA Basic Gradient",
|
||||
"10900",
|
||||
): "files/5a241ce2f6c79abb9cfe3cb1414f1bf1.png?v=1745376969&width=144",
|
||||
(
|
||||
"PLA Basic Gradient",
|
||||
"10901",
|
||||
): "files/e40cbbf6e7fed96557d8e2be99e4b9cf.png?v=1745376969&width=144",
|
||||
(
|
||||
"PLA Glow",
|
||||
"15300",
|
||||
): "files/e40cbbf6e7fed96557d8e2be99e4b9cf_874f9392-3fe3-4c65-87cc-91b158674eb3.png?v=1741591652&width=144",
|
||||
("PLA Glow", "15400"): "files/6fdaecdc33b9371fb7c326d4bd52932b.png?v=1741591652&width=144",
|
||||
(
|
||||
"PLA Glow",
|
||||
"15500",
|
||||
): "files/4fefbcd44633bcd5e4f4663eafb78c3c_cb3f9dbb-235b-4e7d-83ab-6cbecb7aa5bf.png?v=1741591652&width=144",
|
||||
(
|
||||
"PLA Glow",
|
||||
"15200",
|
||||
): "files/5d4ad98b7e6fd7642323ef49163d8697_0f3e6424-4115-4337-952a-bedfc997a747.png?v=1741320466&width=144",
|
||||
(
|
||||
"PLA Glow",
|
||||
"15600",
|
||||
): "files/697ef5c2066bf49f4df46a227b1a93c1_7e4c0733-bbcc-4258-9a3f-7d178fb91191.png?v=1741320466&width=144",
|
||||
("PLA Galaxy", "13602"): "files/purle.jpg?v=1741591770&width=144",
|
||||
("PLA Galaxy", "13503"): "files/green.jpg?v=1741141183&width=144",
|
||||
("PLA Galaxy", "13504"): "files/Nublae.jpg?v=1741141183&width=144",
|
||||
("PLA Galaxy", "13203"): "files/brown.jpg?v=1741141183&width=144",
|
||||
(
|
||||
"PLA Wood",
|
||||
"13505",
|
||||
): "files/5_335a103f-01a9-4d9e-90e1-f09e885ea39a.jpg?v=1741591590&width=144",
|
||||
(
|
||||
"PLA Wood",
|
||||
"13107",
|
||||
): "files/4_4f1d41bd-761c-4ac8-bea1-540852b7334d.jpg?v=1741591590&width=144",
|
||||
(
|
||||
"PLA Wood",
|
||||
"13204",
|
||||
): "files/2_a72cb84b-e92c-4efa-a205-589184265d78.jpg?v=1741320520&width=144",
|
||||
(
|
||||
"PLA Wood",
|
||||
"13801",
|
||||
): "files/3_37397ab4-e4dc-4e75-98f9-b69f78c4b142.jpg?v=1741320520&width=144",
|
||||
(
|
||||
"PLA Wood",
|
||||
"13106",
|
||||
): "files/1_8a574e02-b803-4e36-b895-8bb70529a014.jpg?v=1741141222&width=144",
|
||||
(
|
||||
"PLA Wood",
|
||||
"13403",
|
||||
): "files/6_ef2119c0-2b6b-4853-8812-03e097822ad9.jpg?v=1741141222&width=144",
|
||||
("PLA Metal", "13600"): "files/A02-B2-1.75-1000-spl.png?v=1741591713&width=144",
|
||||
("PLA Metal", "13500"): "products/PLA-Metal_Oxide-Green-Metallic.png?v=1741141209&width=144",
|
||||
("PLA Metal", "13400"): "products/PLA-Metal_Iridium-Gold-Metallic.png?v=1741141209&width=144",
|
||||
("PLA Metal", "13800"): "files/PLAMetalcopperbrown.png?v=1741141209&width=144",
|
||||
("PLA Metal", "13100"): "files/PLAMetalIrongray.png?v=1741141209&width=144",
|
||||
("ASA", "45500"): "files/ab6743fac3b96abc3a53833a12993981.png?v=1741591687&width=144",
|
||||
("ASA", "45200"): "files/RED.png?v=1741591687&width=144",
|
||||
("ASA", "45600"): "files/ASABlue.jpg?v=1741591687&width=144",
|
||||
("ASA", "45100"): "files/white.png?v=1741591687&width=144",
|
||||
("ASA", "45102"): "files/gray.png?v=1741320571&width=144",
|
||||
("ASA", "45101"): "files/black.png?v=1741320571&width=144",
|
||||
(
|
||||
"PLA Aero",
|
||||
"14102",
|
||||
): "files/AERO_bc503e27-6fed-4b8e-a505-342f6050dc27.png?v=1741591669&width=144",
|
||||
("PLA Aero", "14104"): "files/Aero_1.png?v=1741591669&width=144",
|
||||
("PLA Sparkle", "13501"): "files/Sparklegreen.png?v=1717413555&width=144",
|
||||
("PLA Sparkle", "13102"): "files/PLASparkle-SlateGray.png?v=1717494865&width=144",
|
||||
("PLA Sparkle", "13700"): "files/PLASparkle-RoyalPurpleSparkle.png?v=1717491289&width=144",
|
||||
("PLA Sparkle", "13200"): "products/PLA-Sparkle_Crimson-Red-Sparkle.png?v=1717491289&width=144",
|
||||
("PLA Sparkle", "13101"): "products/PLA-Sparkle_Onyx-Black-Sparkle.png?v=1717491289&width=144",
|
||||
("PLA Sparkle", "13402"): "files/sparklegold.png?v=1717491289&width=144",
|
||||
("PLA Marble", "13201"): "files/A07-R5-1.75-1000-spl.jpg?v=1715324339&width=144",
|
||||
("PLA Marble", "13103"): "products/PLA-Marble_White.png?v=1717464204&width=144",
|
||||
("PLA-CF", "14500"): "files/c0f99c4f6c04f5422dcd8db2da060392.png?v=1708912897&width=144",
|
||||
("PLA-CF", "14200"): "files/a607d88492630a4fc0e1169570fcd150.png?v=1717494860&width=144",
|
||||
("PLA-CF", "14600"): "files/5330081a75ef62e73afe0929195b72b8.png?v=1717491303&width=144",
|
||||
("PLA-CF", "14101"): "files/83c1bc164a2861ecc083568a0b017ba0.png?v=1717491303&width=144",
|
||||
("PLA-CF", "14100"): "files/PLA-CFBlack.jpg?v=1717491303&width=144",
|
||||
("PLA-CF", "14601"): "files/PLA-CFRoyalBlue.png?v=1717491303&width=144",
|
||||
("PLA-CF", "14700"): "files/PLA-CFIrisPurple.png?v=1717491303&width=144",
|
||||
(
|
||||
"PETG-CF",
|
||||
"31700",
|
||||
): "files/PETG-CFpurp_37ad5532-5d64-4eb9-90b0-d183f2511e9e.png?v=1701418958&width=144",
|
||||
("PETG-CF", "31500"): "files/PETG-CFgreen.png?v=1710836919&width=144",
|
||||
("PETG-CF", "31600"): "files/PETG-CFblue.png?v=1710836919&width=144",
|
||||
("PETG-CF", "31100"): "files/PETG-CF.png?v=1710836919&width=144",
|
||||
("PETG-CF", "31101"): "files/20231023-105314.png?v=1701418958&width=144",
|
||||
("PETG-CF", "31200"): "files/PETG-CFred.png?v=1710836919&width=144",
|
||||
("ASA Aero", "46100"): "files/asaaeroball.png?v=1712806634&width=144",
|
||||
("PC", "60103"): "files/C00-C1-1.75-1000-spl.png?v=1715323655&width=144",
|
||||
("PC", "60102"): "products/PC_Clear-Black_v2.png?v=1717571828&width=144",
|
||||
("PC", "60101"): "files/PCBlack.png?v=1717571828&width=144",
|
||||
("PC", "60100"): "files/PC_White_1.jpg?v=1733127362&width=144",
|
||||
("PC FR", "63100"): "files/3_2bfbabcc-c211-415c-926b-f5891b308048.jpg?v=1745377204&width=144",
|
||||
("PC FR", "63101"): "files/2_65a3ddbd-13a9-444c-9ec8-7707acb88a62.jpg?v=1745377204&width=144",
|
||||
("PC FR", "63102"): "files/1_a71ee34c-988e-42db-b355-224daf27e489.jpg?v=1745377204&width=144",
|
||||
("TPU for AMS", "53600"): "files/d4fb1dd751904e1ea09d142c68d7ec36.jpg?v=1738741086&width=144",
|
||||
(
|
||||
"TPU for AMS",
|
||||
"53102",
|
||||
): "files/1_5375ac46-09e0-4b5e-b708-89c44a7ac151.jpg?v=1738741086&width=144",
|
||||
("TPU for AMS", "53101"): "files/7.jpg?v=1738741086&width=144",
|
||||
(
|
||||
"TPU for AMS",
|
||||
"53400",
|
||||
): "files/3_ceb63b89-77a8-4055-a4fa-5aad0dda7d0e.jpg?v=1738741086&width=144",
|
||||
(
|
||||
"TPU for AMS",
|
||||
"53200",
|
||||
): "files/2_907c4fb7-2389-4459-9751-ee8dbcf01b1d.jpg?v=1738741086&width=144",
|
||||
(
|
||||
"TPU for AMS",
|
||||
"53500",
|
||||
): "files/5_edbdfcc8-87bc-446a-ac5d-0693f01cb177.jpg?v=1738741086&width=144",
|
||||
(
|
||||
"TPU for AMS",
|
||||
"53100",
|
||||
): "files/4_74fce0cf-2101-4222-8582-53a2ed58dad4.jpg?v=1738741086&width=144",
|
||||
("TPU 95A HF", "51102"): "files/TPUHF_1.png?v=1741592397&width=144",
|
||||
("TPU 95A HF", "51101"): "files/TPUHF_5.png?v=1741592397&width=144",
|
||||
("TPU 95A HF", "51400"): "files/TPUHF_4.png?v=1741084471&width=144",
|
||||
("TPU 95A HF", "51600"): "files/TPUHF_6.png?v=1741084471&width=144",
|
||||
("TPU 95A HF", "51200"): "files/TPUHF_3.png?v=1741084471&width=144",
|
||||
("TPU 95A HF", "51100"): "files/TPUHF_2.png?v=1741084471&width=144",
|
||||
("ABS-GF", "41300"): "files/JP36183.png?v=1741591603&width=144",
|
||||
("ABS-GF", "41500"): "files/JP36184.png?v=1741084452&width=144",
|
||||
("ABS-GF", "41200"): "files/JP36182.png?v=1741084452&width=144",
|
||||
("ABS-GF", "41400"): "files/JP36196.png?v=1741084452&width=144",
|
||||
("ABS-GF", "41600"): "files/ABSgfblue.png?v=1741084452&width=144",
|
||||
("ABS-GF", "41100"): "files/JP36193.png?v=1741084452&width=144",
|
||||
("ABS-GF", "41102"): "files/JP36190.png?v=1741084452&width=144",
|
||||
("ABS-GF", "41101"): "files/JP36181.png?v=1741084452&width=144",
|
||||
("PA6-GF", "72600"): "files/JP35952.jpg?v=1741591618&width=144",
|
||||
("PA6-GF", "72200"): "files/JP35945.jpg?v=1741084487&width=144",
|
||||
("PA6-GF", "72400"): "files/JP35959_1.jpg?v=1741084487&width=144",
|
||||
("PA6-GF", "72500"): "files/JP35966.jpg?v=1741084487&width=144",
|
||||
("PA6-GF", "72800"): "files/JP35969.jpg?v=1741084487&width=144",
|
||||
("PA6-GF", "72102"): "files/JP35967.jpg?v=1741084487&width=144",
|
||||
("PA6-GF", "72103"): "files/JP35971c.jpg?v=1741084487&width=144",
|
||||
("PA6-GF", "72104"): "files/JP35970c.jpg?v=1741084487&width=144",
|
||||
("PAHT-CF (500 g)", "70100"): "files/PAHTCFORIGINAL.png?v=1684592088&width=144",
|
||||
("PAHT-CF (1 kg)", "70100"): "files/PAHTCFORIGINAL.png?v=1684592088&width=144",
|
||||
("PA6-CF (500 g)", "72100"): "files/PA6-CF.png?v=1693188546&width=144",
|
||||
("PA6-CF (1 kg)", "72100"): "files/PA6-CF.png?v=1693188546&width=144",
|
||||
("PET-CF (500 g)", "71100"): "files/pet-cr.png?v=1685412664&width=144",
|
||||
("PET-CF (1 kg)", "71100"): "files/pet-cr.png?v=1685412664&width=144",
|
||||
("ASA-CF", "46101"): "files/1_db8508ce-9151-474f-8fc4-e57ec533edc0.jpg?v=1727057443&width=144",
|
||||
("PPA-CF", "73100"): "files/PPA1.jpg?v=1724639689&width=144",
|
||||
("PPS-CF", "76100"): "files/Mainimage.png?v=1724636050&width=144",
|
||||
("Support for PLA/PETG", "65103"): "files/supportforplablack.png?v=1740486055&width=144",
|
||||
(
|
||||
"Support for PLA/PETG",
|
||||
"65102",
|
||||
): "files/3_333e81ce-72cf-4643-a79a-19afd5ac5866.jpg?v=1719971678&width=144",
|
||||
("PVA", "66400"): "files/pvasupport12.jpg?v=1710493422&width=144",
|
||||
("Support for PA/PET", "65500"): "files/SupportforPAPET.png?v=1687658143&width=144",
|
||||
("Support for ABS", "66100"): "files/20240704-172034.png?v=1721114913&width=144",
|
||||
}
|
||||
|
||||
|
||||
def bambu_image_url(product, color_key, spool_type):
|
||||
if (product, color_key, spool_type) == ("PLA Basic", "10100", "spool"):
|
||||
return (
|
||||
"https://store.bblcdn.eu/s8/default/0e0f2442945b482eac4ecb20182faf6b/"
|
||||
"pla_baisc_white.jpg"
|
||||
)
|
||||
path = IMAGE_PATHS.get((product, color_key))
|
||||
return SHOPIFY_IMAGES + path if path else ""
|
||||
@@ -0,0 +1,274 @@
|
||||
"""Bambu Lab EU swatches used by migration 0005 and the initial catalog.
|
||||
|
||||
Source: https://bambulab-eu.myshopify.com/collections/bambu-lab-3d-printer-filament
|
||||
Product-page hex tables and the PDFs linked from PLA Basic, Matte and Translucent.
|
||||
Keep this snapshot stable for reproducible migrations.
|
||||
"""
|
||||
|
||||
BAMBU_SWATCHES = {
|
||||
"PLA Translucent": {
|
||||
"13210": "#B50011",
|
||||
"13211": "#F5B6CD",
|
||||
"13301": "#F74E02",
|
||||
"13410": "#F5DBAB",
|
||||
"13510": "#96D8AF",
|
||||
"13610": "#B8CDE9",
|
||||
"13611": "#0047BB",
|
||||
"13612": "#009FA1",
|
||||
"13710": "#8344B0",
|
||||
"13711": "#B8ACD6",
|
||||
},
|
||||
"PLA Basic": {
|
||||
"10100": "#FFFFFF",
|
||||
"10101": "#000000",
|
||||
"10102": "#A6A9AA",
|
||||
"10103": "#8E9089",
|
||||
"10104": "#D1D3D5",
|
||||
"10105": "#545454",
|
||||
"10200": "#C12E1F",
|
||||
"10201": "#F7E6DE",
|
||||
"10202": "#EC008C",
|
||||
"10203": "#F55A74",
|
||||
"10204": "#F5547C",
|
||||
"10205": "#9D2235",
|
||||
"10300": "#FF6A13",
|
||||
"10301": "#FF9016",
|
||||
"10400": "#F4EE2A",
|
||||
"10401": "#E4BD68",
|
||||
"10402": "#FEC600",
|
||||
"10501": "#00AE42",
|
||||
"10502": "#3F8E43",
|
||||
"10503": "#BECF00",
|
||||
"10601": "#0A2989",
|
||||
"10602": "#5B6579",
|
||||
"10603": "#0086D6",
|
||||
"10604": "#0056B8",
|
||||
"10605": "#00B1B7",
|
||||
"10700": "#5E43B7",
|
||||
"10701": "#482960",
|
||||
"10800": "#9D432C",
|
||||
"10801": "#847D48",
|
||||
"10802": "#6F5034",
|
||||
},
|
||||
"PLA Matte": {
|
||||
"11100": "#FFFFFF",
|
||||
"11101": "#000000",
|
||||
"11102": "#9B9EA0",
|
||||
"11103": "#CBC6B8",
|
||||
"11104": "#757575",
|
||||
"11200": "#DE4343",
|
||||
"11201": "#E8AFCF",
|
||||
"11202": "#BB3D43",
|
||||
"11203": "#B15533",
|
||||
"11204": "#950051",
|
||||
"11300": "#F99963",
|
||||
"11400": "#F7D959",
|
||||
"11401": "#E8DBB7",
|
||||
"11500": "#61C680",
|
||||
"11501": "#68724D",
|
||||
"11502": "#C2E189",
|
||||
"11600": "#0078BF",
|
||||
"11601": "#A3D8E1",
|
||||
"11602": "#042F56",
|
||||
"11603": "#56B7E6",
|
||||
"11700": "#AE96D4",
|
||||
"11800": "#D3B7A7",
|
||||
"11801": "#7D6556",
|
||||
"11802": "#4D3324",
|
||||
"11803": "#AE835B",
|
||||
},
|
||||
"PLA Silk+": {
|
||||
"13108": "#5F6367",
|
||||
"13109": "#C8C8C8",
|
||||
"13110": "#FFFFFF",
|
||||
"13205": "#D02727",
|
||||
"13206": "#BA9594",
|
||||
"13207": "#F7ADA6",
|
||||
"13404": "#F3CFB2",
|
||||
"13405": "#F4A925",
|
||||
"13506": "#018814",
|
||||
"13507": "#96DCB9",
|
||||
"13603": "#A8C6EE",
|
||||
"13604": "#008BDA",
|
||||
"13702": "#8671CB",
|
||||
},
|
||||
"PETG HF": {
|
||||
"33100": "#FFFFFF",
|
||||
"33101": "#ADB1B2",
|
||||
"33102": "#000000",
|
||||
"33103": "#515151",
|
||||
"33200": "#EB3A3A",
|
||||
"33300": "#F75403",
|
||||
"33400": "#FFD00B",
|
||||
"33401": "#F9DFB9",
|
||||
"33500": "#00AE42",
|
||||
"33501": "#6EE53C",
|
||||
"33502": "#39541A",
|
||||
"33600": "#002E96",
|
||||
"33601": "#1F79E5",
|
||||
"33801": "#875718",
|
||||
},
|
||||
"PETG Translucent": {
|
||||
"32100": "#8E8E8E",
|
||||
"32200": "#F9C1BD",
|
||||
"32300": "#FF911A",
|
||||
"32500": "#748C45",
|
||||
"32501": "#77EDD7",
|
||||
"32600": "#61B0FF",
|
||||
"32700": "#D6ABFF",
|
||||
"32800": "#C9A381",
|
||||
},
|
||||
"ABS": {
|
||||
"40100": "#FFFFFF",
|
||||
"40101": "#000000",
|
||||
"40102": "#87909A",
|
||||
"40200": "#D32941",
|
||||
"40300": "#FF6A13",
|
||||
"40402": "#FFC72C",
|
||||
"40500": "#00AE42",
|
||||
"40502": "#789D4A",
|
||||
"40600": "#0A2CA5",
|
||||
"40601": "#489FDF",
|
||||
"40602": "#0C2340",
|
||||
},
|
||||
"TPU 90A": {
|
||||
"51103": "#000000",
|
||||
"51105": "#FFFFFF",
|
||||
"51900": "#FFFFFF,#40B6E4",
|
||||
"51901": "#F1AAA8,#D21B3C",
|
||||
},
|
||||
"TPU 85A": {
|
||||
"51305": "#F68B1B",
|
||||
"51500": "#C3E2D6",
|
||||
},
|
||||
"PLA Silk Dual Color": {
|
||||
"Velvet Eclipse (Black-Red)": "#000000,#A34342",
|
||||
"Neon City (Blue-Magenta)": "#0047BB,#BB22A3",
|
||||
"Midnight Blaze (Blue-Red)": "#0047BB,#7D1B49",
|
||||
"Gilded Rose (Pink-Gold)": "#FF9425,#FCA2BF",
|
||||
"Blue Hawaii (Blue-Green)": "#60A4E8,#4CE4A0",
|
||||
},
|
||||
"PLA Basic Gradient": {
|
||||
"10900": "#9CDBD9,#FFFFFF",
|
||||
"10901": "#E94B3C,#FFFFFF",
|
||||
"10902": "#307FE2,#54FF9B",
|
||||
"10903": "#F78F77,#E4505A",
|
||||
"10904": "#B6FF43,#4EC939",
|
||||
"10905": "#6FCAEF,#8573DD",
|
||||
"10906": "#ED9558,#CE4406",
|
||||
"10907": "#E7C1D5,#8EC9E9",
|
||||
},
|
||||
"PLA Glow": {
|
||||
"15200": "#F17B8F",
|
||||
"15300": "#FF9D5B",
|
||||
"15400": "#F8FF80",
|
||||
"15500": "#A1FFAC",
|
||||
"15600": "#7AC0E9",
|
||||
},
|
||||
"PLA Galaxy": {
|
||||
"13203": "#684A43",
|
||||
"13503": "#3B665E",
|
||||
"13504": "#424379",
|
||||
"13602": "#594177",
|
||||
},
|
||||
"PLA Wood": {
|
||||
"13106": "#D6CCA3",
|
||||
"13107": "#4F3F24",
|
||||
"13204": "#4C241C",
|
||||
"13403": "#C98935",
|
||||
"13505": "#918669",
|
||||
"13801": "#995F11",
|
||||
},
|
||||
"PLA Metal": {
|
||||
"13100": "#43403D",
|
||||
"13400": "#B39B84",
|
||||
"13500": "#1D7C6A",
|
||||
"13600": "#39699E",
|
||||
"13800": "#AA6443",
|
||||
},
|
||||
"ASA": {
|
||||
"45100": "#FFFAF2",
|
||||
"45101": "#000000",
|
||||
"45102": "#8A949E",
|
||||
"45200": "#E02928",
|
||||
"45500": "#00A6A0",
|
||||
"45600": "#2140B4",
|
||||
},
|
||||
"PLA Sparkle": {
|
||||
"13101": "#2D2B28",
|
||||
"13102": "#8E9089",
|
||||
"13200": "#792B36",
|
||||
"13402": "#CEA629",
|
||||
"13501": "#3F5443",
|
||||
"13700": "#483D8B",
|
||||
},
|
||||
"PLA Marble": {
|
||||
"13103": "#F7F3F0",
|
||||
"13201": "#AD4E38",
|
||||
},
|
||||
"PLA-CF": {
|
||||
"14100": "#000000",
|
||||
"14101": "#4D5054",
|
||||
"14200": "#951E23",
|
||||
"14500": "#5C9748",
|
||||
"14600": "#6E88BC",
|
||||
"14601": "#2842AD",
|
||||
"14700": "#69398E",
|
||||
},
|
||||
"PETG-CF": {
|
||||
"31100": "#000000",
|
||||
"31101": "#565656",
|
||||
"31200": "#9F332A",
|
||||
"31500": "#16B08E",
|
||||
"31600": "#324585",
|
||||
"31700": "#583061",
|
||||
},
|
||||
"ASA Aero": {
|
||||
"46100": "#FFFAF2",
|
||||
},
|
||||
"PC FR": {
|
||||
"63100": "#000000",
|
||||
"63101": "#FFFFFF",
|
||||
"63102": "#A8A8AA",
|
||||
},
|
||||
"TPU for AMS": {
|
||||
"53100": "#FFFFFF",
|
||||
"53101": "#000000",
|
||||
"53102": "#939393",
|
||||
"53200": "#ED0000",
|
||||
"53400": "#F9EF41",
|
||||
"53500": "#90FF1A",
|
||||
"53600": "#5898DD",
|
||||
},
|
||||
"TPU 95A HF": {
|
||||
"51100": "#101820",
|
||||
"51101": "#898D8D",
|
||||
"51102": "#FFFFFF",
|
||||
"51200": "#C8102E",
|
||||
"51400": "#F3E600",
|
||||
"51600": "#0072CE",
|
||||
},
|
||||
"ABS-GF": {
|
||||
"41100": "#FFFFFF",
|
||||
"41101": "#000000",
|
||||
"41102": "#C6C6C6",
|
||||
"41200": "#E83100",
|
||||
"41300": "#F48438",
|
||||
"41400": "#FFE133",
|
||||
"41500": "#61BF36",
|
||||
"41600": "#0C3B95",
|
||||
},
|
||||
"PA6-GF": {
|
||||
"72102": "#EAEAE4",
|
||||
"72103": "#353533",
|
||||
"72104": "#000000",
|
||||
"72200": "#FF4800",
|
||||
"72400": "#FFCE00",
|
||||
"72500": "#C5ED48",
|
||||
"72600": "#75AED8",
|
||||
"72800": "#5B492F",
|
||||
},
|
||||
"PVA": {
|
||||
"66400": "#F0F1A8",
|
||||
},
|
||||
}
|
||||
+26
-2
@@ -1,7 +1,7 @@
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from .models import Color, Manufacturer, Printer, ProductType, Variant
|
||||
from .models import Color, Feedback, Manufacturer, Printer, ProductType, Variant
|
||||
|
||||
|
||||
def selection_id(value):
|
||||
@@ -21,10 +21,25 @@ class PrinterForm(forms.ModelForm):
|
||||
fields = ["manufacturer", "model", "name"]
|
||||
|
||||
|
||||
class FeedbackForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Feedback
|
||||
fields = ["message"]
|
||||
widgets = {"message": forms.Textarea(attrs={"rows": 6})}
|
||||
|
||||
|
||||
class QuantityForm(forms.Form):
|
||||
quantity = forms.IntegerField(label="Stückzahl", min_value=1, max_value=9999)
|
||||
|
||||
|
||||
class ColorSelect(forms.Select):
|
||||
def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
|
||||
option = super().create_option(name, value, label, selected, index, subindex, attrs)
|
||||
if value and (swatch := self.swatches.get(value.instance.pk)):
|
||||
option["attrs"]["data-swatch"] = swatch
|
||||
return option
|
||||
|
||||
|
||||
class VariantSelectionForm(forms.Form):
|
||||
manufacturer = forms.ModelChoiceField(
|
||||
label="Hersteller", queryset=Manufacturer.objects.none(), empty_label="Hersteller wählen"
|
||||
@@ -33,7 +48,10 @@ class VariantSelectionForm(forms.Form):
|
||||
label="Produktart", queryset=ProductType.objects.none(), empty_label="Produktart wählen"
|
||||
)
|
||||
color = forms.ModelChoiceField(
|
||||
label="Farbe", queryset=Color.objects.none(), empty_label="Farbe wählen"
|
||||
label="Farbe",
|
||||
queryset=Color.objects.none(),
|
||||
empty_label="Farbe wählen",
|
||||
widget=ColorSelect(attrs={"data-color-select": ""}),
|
||||
)
|
||||
spool_type = forms.ChoiceField(label="Spulenausführung", choices=[])
|
||||
quantity = forms.IntegerField(label="Stückzahl", min_value=1, max_value=9999, initial=1)
|
||||
@@ -55,6 +73,12 @@ class VariantSelectionForm(forms.Form):
|
||||
).distinct()
|
||||
narrowed = active.filter(product_type__manufacturer_id=maker, product_type_id=product)
|
||||
self.fields["color"].queryset = Color.objects.filter(variants__in=narrowed).distinct()
|
||||
# Prefer the spool's preview when the two packaging variants have different values.
|
||||
self.fields["color"].widget.swatches = dict(
|
||||
narrowed.exclude(swatch="")
|
||||
.order_by("spool_type", "pk")
|
||||
.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
|
||||
|
||||
@@ -4,6 +4,8 @@ from django.core.management.base import BaseCommand
|
||||
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_swatches_0005 import BAMBU_SWATCHES
|
||||
from filament.models import CatalogBootstrap, Color, Manufacturer, ProductType, Variant
|
||||
|
||||
BAMBU_LAB_BOOTSTRAP_KEY = "bambu-lab-eu-initial-catalog"
|
||||
@@ -37,6 +39,12 @@ class Command(BaseCommand):
|
||||
spool_type=spool_type,
|
||||
defaults={
|
||||
"manufacturer_color_code": code,
|
||||
"swatch": BAMBU_SWATCHES.get(product_name, {}).get(
|
||||
code or color_name, ""
|
||||
),
|
||||
"image_url": bambu_image_url(
|
||||
product_name, code or color_name, spool_type
|
||||
),
|
||||
"net_weight_g": net_weight_g,
|
||||
"diameter_mm": Decimal("1.75"),
|
||||
},
|
||||
|
||||
@@ -10,9 +10,17 @@ class PrivatePageMiddleware:
|
||||
if not request.path.startswith("/static/"):
|
||||
patch_cache_control(response, private=True, no_store=True, max_age=0)
|
||||
if not request.path.startswith("/admin/"):
|
||||
image_sources = "'self' data:"
|
||||
if request.resolver_match and request.resolver_match.url_name in {
|
||||
"inventory",
|
||||
"orders",
|
||||
}:
|
||||
image_sources += (
|
||||
" https://cdn.shopify.com https://store.bblcdn.eu https://store.bblcdn.com"
|
||||
)
|
||||
response["Content-Security-Policy"] = (
|
||||
"default-src 'self'; script-src 'self'; style-src 'self'; "
|
||||
"img-src 'self' data:; object-src 'none'; base-uri 'self'; "
|
||||
f"img-src {image_sources}; object-src 'none'; base-uri 'self'; "
|
||||
"form-action 'self'; frame-ancestors 'none'"
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,46 @@
|
||||
# Generated by Django 5.2.19 on 2026-11-14 13:44
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
from filament.bambu_swatches_0005 import BAMBU_SWATCHES
|
||||
|
||||
|
||||
def fill_bambu_swatches(apps, schema_editor):
|
||||
variant_model = apps.get_model("filament", "Variant")
|
||||
variants = variant_model.objects.using(schema_editor.connection.alias).filter(
|
||||
product_type__manufacturer__name="Bambu Lab", swatch=""
|
||||
)
|
||||
updates = []
|
||||
for variant in variants.select_related("product_type", "color"):
|
||||
colors = BAMBU_SWATCHES.get(variant.product_type.name, {})
|
||||
if swatch := colors.get(variant.manufacturer_color_code or variant.color.name):
|
||||
variant.swatch = swatch
|
||||
updates.append(variant)
|
||||
variants.bulk_update(updates, ["swatch"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("filament", "0004_catalogbootstrap"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="variant",
|
||||
name="swatch",
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
help_text="Ein Hexwert oder zwei durch ein Komma getrennte Hexwerte.",
|
||||
max_length=15,
|
||||
validators=[
|
||||
django.core.validators.RegexValidator(
|
||||
"\\A#[0-9A-Fa-f]{6}(,#[0-9A-Fa-f]{6})?\\Z",
|
||||
"Bitte einen oder zwei Hexwerte eingeben (z. B. #DE4343 oder #000000,#A34342).",
|
||||
)
|
||||
],
|
||||
verbose_name="Farbvorschau",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(fill_bambu_swatches, migrations.RunPython.noop),
|
||||
]
|
||||
@@ -0,0 +1,50 @@
|
||||
# Generated by Django 5.2.19 on 2026-11-14 13:53
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
from filament.bambu_images_0006 import bambu_image_url
|
||||
|
||||
|
||||
def fill_bambu_images(apps, schema_editor):
|
||||
variant_model = apps.get_model("filament", "Variant")
|
||||
variants = variant_model.objects.using(schema_editor.connection.alias).filter(
|
||||
product_type__manufacturer__name="Bambu Lab", image_url=""
|
||||
)
|
||||
updates = []
|
||||
for variant in variants.select_related("product_type", "color"):
|
||||
image = bambu_image_url(
|
||||
variant.product_type.name,
|
||||
variant.manufacturer_color_code or variant.color.name,
|
||||
variant.spool_type,
|
||||
)
|
||||
if image:
|
||||
variant.image_url = image
|
||||
updates.append(variant)
|
||||
variants.bulk_update(updates, ["image_url"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("filament", "0005_variant_swatch"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="variant",
|
||||
name="image_url",
|
||||
field=models.URLField(
|
||||
blank=True,
|
||||
help_text="Bildadresse von cdn.shopify.com, store.bblcdn.eu oder store.bblcdn.com.",
|
||||
max_length=500,
|
||||
validators=[
|
||||
django.core.validators.RegexValidator(
|
||||
"\\Ahttps://(?:cdn\\.shopify\\.com|store\\.bblcdn\\.eu|store\\.bblcdn\\.com)/",
|
||||
"Bitte eine HTTPS-Bildadresse von einer unterstützten CDN-Domain eingeben.",
|
||||
)
|
||||
],
|
||||
verbose_name="Produktbild",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(fill_bambu_images, migrations.RunPython.noop),
|
||||
]
|
||||
@@ -0,0 +1,41 @@
|
||||
# Generated by Django 5.2.19 on 2026-11-14 14:07
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("filament", "0006_variant_image"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Feedback",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
||||
),
|
||||
),
|
||||
("message", models.TextField(max_length=2000, verbose_name="Nachricht")),
|
||||
("created_at", models.DateTimeField(auto_now_add=True, verbose_name="Gesendet am")),
|
||||
(
|
||||
"sender",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="Absender",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Feedback",
|
||||
"verbose_name_plural": "Feedback",
|
||||
"ordering": ["-created_at", "-pk"],
|
||||
},
|
||||
),
|
||||
]
|
||||
+38
-1
@@ -1,5 +1,5 @@
|
||||
from django.conf import settings
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
||||
from django.db import models
|
||||
|
||||
|
||||
@@ -60,6 +60,30 @@ class Variant(models.Model):
|
||||
)
|
||||
spool_type = models.CharField("Spulenausführung", max_length=10, choices=SpoolType.choices)
|
||||
manufacturer_color_code = models.CharField("Hersteller-Farbcode", max_length=40, blank=True)
|
||||
swatch = models.CharField(
|
||||
"Farbvorschau",
|
||||
max_length=15,
|
||||
blank=True,
|
||||
validators=[
|
||||
RegexValidator(
|
||||
r"\A#[0-9A-Fa-f]{6}(,#[0-9A-Fa-f]{6})?\Z",
|
||||
"Bitte einen oder zwei Hexwerte eingeben (z. B. #DE4343 oder #000000,#A34342).",
|
||||
)
|
||||
],
|
||||
help_text="Ein Hexwert oder zwei durch ein Komma getrennte Hexwerte.",
|
||||
)
|
||||
image_url = models.URLField(
|
||||
"Produktbild",
|
||||
max_length=500,
|
||||
blank=True,
|
||||
validators=[
|
||||
RegexValidator(
|
||||
r"\Ahttps://(?:cdn\.shopify\.com|store\.bblcdn\.eu|store\.bblcdn\.com)/",
|
||||
"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.",
|
||||
)
|
||||
net_weight_g = models.PositiveIntegerField(
|
||||
"Nettogewicht (g)", null=True, blank=True, validators=[MinValueValidator(1)]
|
||||
)
|
||||
@@ -163,3 +187,16 @@ class CatalogBootstrap(models.Model):
|
||||
|
||||
key = models.CharField(max_length=100, unique=True)
|
||||
applied_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class Feedback(models.Model):
|
||||
sender = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="Absender"
|
||||
)
|
||||
message = models.TextField("Nachricht", max_length=2000)
|
||||
created_at = models.DateTimeField("Gesendet am", auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-created_at", "-pk"]
|
||||
verbose_name = "Feedback"
|
||||
verbose_name_plural = "Feedback"
|
||||
@@ -43,7 +43,8 @@ a:hover {
|
||||
}
|
||||
button,
|
||||
input,
|
||||
select {
|
||||
select,
|
||||
textarea {
|
||||
font: inherit;
|
||||
}
|
||||
button,
|
||||
@@ -386,6 +387,40 @@ td.quantity {
|
||||
font-weight: 700;
|
||||
color: var(--green);
|
||||
}
|
||||
.variant-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-width: 8rem;
|
||||
}
|
||||
.article-number {
|
||||
font-variant-numeric: tabular-nums;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.variant-thumbnail {
|
||||
position: relative;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex: 0 0 48px;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: var(--surface-solid);
|
||||
color: var(--green);
|
||||
}
|
||||
.variant-thumbnail-placeholder {
|
||||
font-size: 22px;
|
||||
}
|
||||
.variant-thumbnail img {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
}
|
||||
.actions {
|
||||
white-space: nowrap;
|
||||
font-size: 12px;
|
||||
@@ -426,6 +461,9 @@ td.quantity {
|
||||
padding: 28px;
|
||||
max-width: 850px;
|
||||
}
|
||||
.variant-panel {
|
||||
overflow: visible;
|
||||
}
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
@@ -444,7 +482,8 @@ td.quantity {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.field input,
|
||||
.field select {
|
||||
.field select,
|
||||
.field textarea {
|
||||
width: 100%;
|
||||
padding: 11px 12px;
|
||||
border: 1px solid #7c979e;
|
||||
@@ -453,9 +492,76 @@ td.quantity {
|
||||
color: var(--ink);
|
||||
min-height: 44px;
|
||||
}
|
||||
.field textarea {
|
||||
display: block;
|
||||
resize: vertical;
|
||||
}
|
||||
.field input:disabled {
|
||||
background: var(--paper);
|
||||
}
|
||||
.color-picker {
|
||||
position: relative;
|
||||
}
|
||||
.color-trigger,
|
||||
.color-choices button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 9px 12px;
|
||||
color: var(--ink);
|
||||
text-align: left;
|
||||
}
|
||||
.color-trigger {
|
||||
border: 1px solid #7c979e;
|
||||
border-radius: 10px;
|
||||
background: rgb(255 255 255 / 84%);
|
||||
}
|
||||
.color-trigger::after {
|
||||
content: "";
|
||||
flex: 0 0 7px;
|
||||
height: 7px;
|
||||
margin: 0 4px 4px auto;
|
||||
border-right: 2px solid var(--muted);
|
||||
border-bottom: 2px solid var(--muted);
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
.color-choices {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
inset: calc(100% + 6px) 0 auto;
|
||||
max-height: min(16rem, 50vh);
|
||||
overflow-y: auto;
|
||||
padding: 5px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
background: var(--surface-solid);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.color-choices button {
|
||||
border: 0;
|
||||
border-radius: 7px;
|
||||
background: transparent;
|
||||
}
|
||||
.color-choices button:hover,
|
||||
.color-choices button[aria-pressed="true"] {
|
||||
background: var(--light);
|
||||
}
|
||||
.color-choices button:focus-visible {
|
||||
outline-offset: -3px;
|
||||
}
|
||||
.color-dot {
|
||||
display: inline-block;
|
||||
flex: 0 0 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 1px solid rgb(20 47 55 / 40%);
|
||||
border-radius: 50%;
|
||||
}
|
||||
.color-dot--unknown {
|
||||
border: 1px dashed #7c979e;
|
||||
}
|
||||
.field small,
|
||||
.helptext {
|
||||
color: var(--muted);
|
||||
|
||||
@@ -1,4 +1,126 @@
|
||||
"use strict";
|
||||
|
||||
document.querySelectorAll(".variant-thumbnail img").forEach((image) => {
|
||||
image.addEventListener("error", () => image.remove(), { once: true });
|
||||
if (image.complete && image.naturalWidth === 0) image.remove();
|
||||
});
|
||||
|
||||
function enhanceColorSelect(select) {
|
||||
const options = [...select.options].filter((option) => option.value && !option.disabled);
|
||||
if (!options.some((option) => option.dataset.swatch)) return;
|
||||
|
||||
const label = select.labels[0];
|
||||
const picker = document.createElement("div");
|
||||
picker.className = "color-picker";
|
||||
const trigger = document.createElement("button");
|
||||
trigger.type = "button";
|
||||
trigger.id = select.id + "-trigger";
|
||||
trigger.className = "color-trigger";
|
||||
const list = document.createElement("div");
|
||||
list.id = select.id + "-choices";
|
||||
list.className = "color-choices";
|
||||
list.hidden = true;
|
||||
list.setAttribute("role", "group");
|
||||
trigger.setAttribute("aria-controls", list.id);
|
||||
trigger.setAttribute("aria-expanded", "false");
|
||||
|
||||
const caption = document.createElement("span");
|
||||
caption.id = trigger.id + "-value";
|
||||
label.id ||= select.id + "-label";
|
||||
trigger.setAttribute("aria-labelledby", label.id + " " + caption.id);
|
||||
list.setAttribute("aria-labelledby", label.id);
|
||||
for (const attr of ["aria-invalid", "aria-describedby"]) {
|
||||
if (select.hasAttribute(attr)) trigger.setAttribute(attr, select.getAttribute(attr));
|
||||
}
|
||||
|
||||
function swatch(option) {
|
||||
const dot = document.createElement("span");
|
||||
dot.className = "color-dot";
|
||||
dot.setAttribute("aria-hidden", "true");
|
||||
const value = option?.dataset.swatch;
|
||||
if (value && /^#[0-9a-f]{6}(,#[0-9a-f]{6})?$/i.test(value)) {
|
||||
const [first, second] = value.split(",");
|
||||
dot.style.background = second
|
||||
? `linear-gradient(135deg, ${first} 48%, ${second} 52%)`
|
||||
: first;
|
||||
} else {
|
||||
dot.classList.add("color-dot--unknown");
|
||||
}
|
||||
return dot;
|
||||
}
|
||||
|
||||
function updateTrigger() {
|
||||
const option = select.selectedOptions[0];
|
||||
caption.textContent = option?.textContent || "Farbe wählen";
|
||||
trigger.replaceChildren(swatch(option), caption);
|
||||
}
|
||||
|
||||
function close(restoreFocus = false) {
|
||||
list.hidden = true;
|
||||
trigger.setAttribute("aria-expanded", "false");
|
||||
if (restoreFocus) trigger.focus();
|
||||
}
|
||||
|
||||
const buttons = options.map((option) => {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.setAttribute("aria-pressed", String(option.selected));
|
||||
const name = document.createElement("span");
|
||||
name.textContent = option.textContent;
|
||||
button.append(swatch(option), name);
|
||||
button.addEventListener("click", () => {
|
||||
const changed = select.value !== option.value;
|
||||
select.value = option.value;
|
||||
updateTrigger();
|
||||
buttons.forEach((choice) => choice.setAttribute("aria-pressed", String(choice === button)));
|
||||
close(true);
|
||||
if (changed) select.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
});
|
||||
list.append(button);
|
||||
return button;
|
||||
});
|
||||
|
||||
function open(last = false) {
|
||||
list.hidden = false;
|
||||
trigger.setAttribute("aria-expanded", "true");
|
||||
const selected = options.findIndex((option) => option.selected);
|
||||
buttons[selected >= 0 ? selected : last ? buttons.length - 1 : 0].focus();
|
||||
}
|
||||
|
||||
trigger.addEventListener("click", () => (list.hidden ? open() : close()));
|
||||
picker.addEventListener("keydown", (event) => {
|
||||
const { key } = event;
|
||||
if (key === "Escape" && !list.hidden) {
|
||||
event.preventDefault();
|
||||
close(true);
|
||||
} else if (key === "ArrowDown" || key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
const index = buttons.indexOf(document.activeElement);
|
||||
if (list.hidden || index < 0) open(key === "ArrowUp");
|
||||
else buttons[Math.min(buttons.length - 1, Math.max(0, index + (key === "ArrowDown" ? 1 : -1)))].focus();
|
||||
} else if (!list.hidden && (key === "Home" || key === "End")) {
|
||||
event.preventDefault();
|
||||
buttons[key === "Home" ? 0 : buttons.length - 1].focus();
|
||||
}
|
||||
});
|
||||
picker.addEventListener("focusout", (event) => {
|
||||
if (!picker.contains(event.relatedTarget)) close();
|
||||
});
|
||||
document.addEventListener("pointerdown", (event) => {
|
||||
if (!picker.contains(event.target)) close();
|
||||
});
|
||||
|
||||
select.addEventListener("invalid", (event) => {
|
||||
event.preventDefault();
|
||||
open();
|
||||
});
|
||||
updateTrigger();
|
||||
picker.append(trigger, list);
|
||||
select.after(picker);
|
||||
label.htmlFor = trigger.id;
|
||||
select.hidden = true;
|
||||
}
|
||||
|
||||
const form = document.querySelector("[data-catalog-form]");
|
||||
if (form) {
|
||||
const selects = [...form.querySelectorAll("select")];
|
||||
@@ -10,4 +132,6 @@ if (form) {
|
||||
form.requestSubmit(form.querySelector("[data-filter-button]"));
|
||||
});
|
||||
});
|
||||
const colorSelect = form.querySelector("[data-color-select]");
|
||||
if (colorSelect) enhanceColorSelect(colorSelect);
|
||||
}
|
||||
@@ -19,6 +19,28 @@ class CatalogTests(CatalogTestCase):
|
||||
def setUp(self):
|
||||
self.client.force_login(self.alice)
|
||||
|
||||
def test_lists_show_product_images_and_placeholder_for_missing_photo(self):
|
||||
image_url = "https://cdn.shopify.com/example.png"
|
||||
self.spool.image_url = image_url
|
||||
self.spool.manufacturer_color_code = "11200"
|
||||
self.spool.save(update_fields=["image_url", "manufacturer_color_code"])
|
||||
for model in (InventoryItem, OrderItem):
|
||||
model.objects.create(owner=self.alice, variant=self.spool, quantity=1)
|
||||
model.objects.create(owner=self.alice, variant=self.refill, quantity=1)
|
||||
|
||||
for url in ("/bestand/", "/bestellung/"):
|
||||
response = self.client.get(url)
|
||||
self.assertContains(response, 'class="variant-thumbnail"', count=2)
|
||||
self.assertContains(response, f'src="{image_url}"', count=1)
|
||||
self.assertContains(response, 'referrerpolicy="no-referrer"', count=1)
|
||||
self.assertContains(response, '<th title="Hersteller-Farbcode">Artikelnr.</th>')
|
||||
self.assertContains(response, '<td class="article-number">11200</td>', count=1)
|
||||
self.assertContains(response, '<td class="article-number">–</td>', count=1)
|
||||
self.assertIn("https://cdn.shopify.com", response["Content-Security-Policy"])
|
||||
self.assertNotIn(
|
||||
"https://cdn.shopify.com", self.client.get("/katalog/")["Content-Security-Policy"]
|
||||
)
|
||||
|
||||
def test_shared_catalog_displays_optional_variant_data(self):
|
||||
self.spool.manufacturer_color_code = "11200"
|
||||
self.spool.net_weight_g = 1000
|
||||
@@ -62,6 +84,24 @@ class CatalogTests(CatalogTestCase):
|
||||
self.assertContains(response, "formnovalidate")
|
||||
self.assertFalse(InventoryItem.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"])
|
||||
for url in ("/bestand/hinzufuegen/", "/bestellung/hinzufuegen/"):
|
||||
with self.subTest(url=url):
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
"manufacturer": self.maker.pk,
|
||||
"product_type": self.product.pk,
|
||||
"action": "filter",
|
||||
},
|
||||
)
|
||||
self.assertContains(response, 'data-color-select=""')
|
||||
self.assertContains(response, 'data-swatch="#DE4343"', count=1)
|
||||
self.assertContains(response, "Kohleschwarz")
|
||||
self.assertFalse(response.context["form"].errors)
|
||||
|
||||
def test_inactive_variants_stay_visible_in_existing_positions_but_cannot_be_added(self):
|
||||
stock = InventoryItem.objects.create(owner=self.alice, variant=self.spool, quantity=2)
|
||||
OrderItem.objects.create(owner=self.bob, variant=self.spool, quantity=1)
|
||||
@@ -90,6 +130,16 @@ class CatalogTests(CatalogTestCase):
|
||||
BAMBU_LAB_PRODUCT_COUNT,
|
||||
)
|
||||
self.assertEqual(Variant.objects.count(), BAMBU_LAB_VARIANT_COUNT)
|
||||
self.assertFalse(
|
||||
Variant.objects.exclude(pk__in=(self.spool.pk, self.refill.pk, self.black_spool.pk))
|
||||
.filter(image_url="")
|
||||
.exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
Variant.objects.get(
|
||||
product_type__name="PLA Basic", manufacturer_color_code="10100", spool_type="spool"
|
||||
).image_url.endswith("/pla_baisc_white.jpg")
|
||||
)
|
||||
for product, color, code, spool_type, weight in (
|
||||
("PLA Basic", "Jade White", "10100", "refill", 1000),
|
||||
("PLA Translucent", "Teal", "13612", "spool", 1000),
|
||||
@@ -109,6 +159,12 @@ class CatalogTests(CatalogTestCase):
|
||||
(product, color, spool_type),
|
||||
)
|
||||
self.assertFalse(ProductType.objects.filter(name__icontains="bundle").exists())
|
||||
self.assertEqual(
|
||||
Variant.objects.get(
|
||||
product_type__name="PLA Silk Dual Color", color__name="Velvet Eclipse (Black-Red)"
|
||||
).swatch,
|
||||
"#000000,#A34342",
|
||||
)
|
||||
count = Variant.objects.count()
|
||||
inactive = Variant.objects.filter(manufacturer_color_code="11100").first()
|
||||
removed = Variant.objects.get(
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from filament.models import Feedback
|
||||
|
||||
|
||||
class FeedbackTests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
users = get_user_model().objects
|
||||
cls.member = users.create_user(username="mitglied")
|
||||
cls.admin = users.create_superuser(username="verwaltung")
|
||||
|
||||
def test_member_can_send_feedback_only_as_themselves(self):
|
||||
url = reverse("feedback")
|
||||
self.assertRedirects(self.client.post(url, {"message": "Test"}), f"/anmelden/?next={url}")
|
||||
self.client.force_login(self.member)
|
||||
self.assertContains(self.client.get(reverse("inventory")), f'href="{url}"')
|
||||
for invalid in (" ", "x" * 2001):
|
||||
response = self.client.post(url, {"message": invalid})
|
||||
self.assertTrue(response.context["form"].errors)
|
||||
self.assertFalse(Feedback.objects.exists())
|
||||
|
||||
response = self.client.post(
|
||||
url, {"message": "Bitte noch eine Farbe ergänzen.", "sender": self.admin.pk}
|
||||
)
|
||||
self.assertRedirects(response, url)
|
||||
entry = Feedback.objects.get()
|
||||
self.assertEqual(entry.sender_id, self.member.pk)
|
||||
self.assertEqual(entry.message, "Bitte noch eine Farbe ergänzen.")
|
||||
self.assertIsNotNone(entry.created_at)
|
||||
self.assertNotContains(self.client.get(url), entry.message)
|
||||
|
||||
def test_only_admin_can_read_private_messages_and_post_requires_csrf(self):
|
||||
body = "<script>alert(1)</script>"
|
||||
entry = Feedback.objects.create(sender=self.member, message=body)
|
||||
detail = reverse("admin:filament_feedback_change", args=[entry.pk])
|
||||
self.client.force_login(self.member)
|
||||
self.assertEqual(self.client.get(detail).status_code, 302)
|
||||
|
||||
csrf_client = Client(enforce_csrf_checks=True)
|
||||
csrf_client.force_login(self.member)
|
||||
self.assertEqual(
|
||||
csrf_client.post(reverse("feedback"), {"message": "Test"}).status_code, 403
|
||||
)
|
||||
|
||||
self.client.force_login(self.admin)
|
||||
self.assertContains(
|
||||
self.client.get(reverse("admin:filament_feedback_changelist")), self.member.username
|
||||
)
|
||||
response = self.client.get(detail)
|
||||
self.assertContains(response, "<script>alert(1)</script>")
|
||||
self.assertEqual(self.client.post(detail, {"message": "Geändert"}).status_code, 403)
|
||||
entry.refresh_from_db()
|
||||
self.assertEqual(entry.message, body)
|
||||
+24
-1
@@ -7,7 +7,7 @@ from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
from .forms import PrinterForm, ProfileForm, QuantityForm, VariantSelectionForm
|
||||
from .forms import FeedbackForm, PrinterForm, ProfileForm, QuantityForm, VariantSelectionForm
|
||||
from .models import InventoryItem, OrderItem, Printer, Variant
|
||||
from .services import add_quantity
|
||||
|
||||
@@ -29,6 +29,29 @@ def profile(request):
|
||||
return render(request, "filament/profile.html", {"form": form})
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def feedback(request):
|
||||
form = FeedbackForm(request.POST if request.method == "POST" else None)
|
||||
if request.method == "POST" and form.is_valid():
|
||||
entry = form.save(commit=False)
|
||||
entry.sender = request.user
|
||||
entry.save()
|
||||
messages.success(request, "Deine Nachricht wurde an die Administration gesendet.")
|
||||
return redirect("feedback")
|
||||
return render(
|
||||
request,
|
||||
"filament/form.html",
|
||||
{
|
||||
"form": form,
|
||||
"title": "Feedback",
|
||||
"description": "Melde ein Problem oder schick einen Wunsch an die Administration.",
|
||||
"back_name": "inventory",
|
||||
"submit_label": "Nachricht senden",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def catalog(request):
|
||||
variants = Variant.objects.filter(is_active=True).select_related(
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
{% if '/bestellung/' in request.path %}aria-current="page"{% endif %}><span class="nav-icon" aria-hidden="true">↗</span><span>Sammelbestellung</span></a>
|
||||
<a href="/katalog/"
|
||||
{% if '/katalog/' in request.path %}aria-current="page"{% endif %}><span class="nav-icon" aria-hidden="true">◫</span><span>Filamentkatalog</span></a>
|
||||
<a href="{% url 'feedback' %}"{% if request.resolver_match.url_name == 'feedback' %} aria-current="page"{% endif %}><span class="nav-icon" aria-hidden="true">✉</span><span>Feedback</span></a>
|
||||
{% if user.is_superuser %}<a href="/admin/"><span class="nav-icon" aria-hidden="true">⚙</span><span>Administration</span></a>{% endif %}
|
||||
</nav>
|
||||
<div class="sidebar-bottom"><a class="profile-link" href="/profil/"{% if request.path == '/profil/' %} aria-current="page"{% endif %}><span class="avatar" aria-hidden="true">{{ user.username|first|upper }}</span><span><strong>{{ user.username }}</strong><small>Mein Profil</small></span></a>
|
||||
|
||||
@@ -1 +1,24 @@
|
||||
{% 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">DEIN PRIVATER BEREICH</p><h1>{{ title }}</h1><p class="muted">{{ description }}</p></div></div><section class="panel form-panel"><form method="post">{% csrf_token %}{{ form.non_field_errors }}{% for field in form %}<div class="field">{{ field.label_tag }}{{ field }}{{ field.errors }}{% if field.help_text %}<div class="helptext">{{ field.help_text }}</div>{% endif %}</div>{% endfor %}<button class="button" type="submit">Speichern</button></form></section>{% endblock %}
|
||||
{% 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">DEIN PRIVATER BEREICH</p>
|
||||
<h1>{{ title }}</h1>
|
||||
<p class="muted">{{ description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<section class="panel form-panel">
|
||||
<form method="post">
|
||||
{% csrf_token %}{{ form.non_field_errors }}
|
||||
{% for field in form %}
|
||||
<div class="field">
|
||||
{{ field.label_tag }}{{ field }}{{ field.errors }}
|
||||
{% if field.help_text %}<div class="helptext" id="{{ field.auto_id }}_helptext">{{ field.help_text }}</div>{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button class="button" type="submit">{{ submit_label|default:"Speichern" }}</button>
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -16,7 +16,17 @@
|
||||
<h2>Dein Vorrat</h2>
|
||||
<span class="badge">{{ items|length }} Position{{ items|length|pluralize:"en" }}</span>
|
||||
</div>
|
||||
{% if items %}<div class="table-wrap"><table><thead><tr><th>Stück</th><th>Hersteller</th><th>Produktart</th><th>Farbe</th><th>Spulenausführung</th><th><span class="sr-only">Aktionen</span></th></tr></thead><tbody>
|
||||
{% for item in items %}<tr><td class="quantity">{{ item.quantity }}</td><td>{{ item.variant.manufacturer }}</td><td>{{ item.variant.product_type.name }}</td><td><strong>{{ item.variant.color }}</strong>{% if item.variant.manufacturer_color_code %}<small>{{ item.variant.manufacturer_color_code }}</small>{% endif %}</td><td><span class="badge">{{ item.variant.get_spool_type_display }}</span>{% if not item.variant.is_active %}<small class="warning">Deaktiviert</small>{% endif %}</td><td class="actions"><a href="/bestand/{{ item.pk }}/bearbeiten/">Ändern</a><a class="danger-link" href="/bestand/{{ item.pk }}/loeschen/">Entfernen</a></td></tr>{% endfor %}
|
||||
{% if items %}<div class="table-wrap"><table><thead><tr><th>Stück</th><th>Hersteller</th><th>Produktart</th><th>Farbe</th><th title="Hersteller-Farbcode">Artikelnr.</th><th>Spulenausführung</th><th><span class="sr-only">Aktionen</span></th></tr></thead><tbody>
|
||||
{% for item in items %}
|
||||
<tr>
|
||||
<td class="quantity">{{ item.quantity }}</td>
|
||||
<td>{{ item.variant.manufacturer }}</td>
|
||||
<td>{{ item.variant.product_type.name }}</td>
|
||||
<td><div class="variant-preview">{% include "filament/variant_thumbnail.html" with variant=item.variant only %}<strong>{{ item.variant.color }}</strong></div></td>
|
||||
<td class="article-number">{{ item.variant.manufacturer_color_code|default:"–" }}</td>
|
||||
<td><span class="badge">{{ item.variant.get_spool_type_display }}</span>{% if not item.variant.is_active %}<small class="warning">Deaktiviert</small>{% endif %}</td>
|
||||
<td class="actions"><a href="/bestand/{{ item.pk }}/bearbeiten/">Ändern</a><a class="danger-link" href="/bestand/{{ item.pk }}/loeschen/">Entfernen</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody></table></div>{% else %}<div class="empty"><span class="empty-icon" aria-hidden="true">◉</span><h3>Platz für dein erstes Filament</h3><p>Wähle eine Variante aus dem gemeinsamen Katalog und lege deinen Vorrat an.</p><a class="button" href="{% url 'inventory_add' %}">Filament auswählen</a></div>{% endif %}</section>
|
||||
<p class="hint">Gut zu wissen: Fügst du dieselbe Variante erneut hinzu, zählen wir die Stückzahl automatisch hoch.</p>{% endblock %}
|
||||
@@ -17,6 +17,15 @@
|
||||
<h2>Eure Bestellübersicht</h2>
|
||||
<span class="badge">Nächste Sammelbestellung</span>
|
||||
</div>
|
||||
{% if groups %}<div class="table-wrap"><table><thead><tr><th>Gesamt</th><th>Filamentvariante</th><th>Spulenausführung</th><th>Aufteilung nach Personen</th></tr></thead><tbody>
|
||||
{% for group in groups %}<tr><td class="quantity">{{ group.total }}</td><td><strong>{{ group.variant.color }}</strong><small>{{ group.variant.manufacturer }} · {{ group.variant.product_type.name }}{% if group.variant.manufacturer_color_code %} · {{ group.variant.manufacturer_color_code }}{% endif %}</small></td><td><span class="badge">{{ group.variant.get_spool_type_display }}</span>{% if not group.variant.is_active %}<small class="warning">Deaktiviert · bestehender Wunsch</small>{% endif %}</td><td>{% for entry in group.entries %}<div class="person">{{ entry.owner.username }}: <strong>{{ entry.quantity }}</strong>{% if entry.owner_id == user.pk %}<span class="actions"> · <a href="{% url 'order_edit' entry.pk %}">Ändern</a> · <a class="danger-link" href="{% url 'order_delete' entry.pk %}">Entfernen</a></span>{% endif %}</div>{% endfor %}</td></tr>{% endfor %}
|
||||
{% if groups %}<div class="table-wrap"><table><thead><tr><th>Gesamt</th><th>Produktart</th><th>Farbe</th><th title="Hersteller-Farbcode">Artikelnr.</th><th>Spulenausführung</th><th>Aufteilung nach Personen</th></tr></thead><tbody>
|
||||
{% for group in groups %}
|
||||
<tr>
|
||||
<td class="quantity">{{ group.total }}</td>
|
||||
<td>{{ group.variant.product_type.name }}<small>{{ group.variant.manufacturer }}</small></td>
|
||||
<td><div class="variant-preview">{% include "filament/variant_thumbnail.html" with variant=group.variant only %}<strong>{{ group.variant.color }}</strong></div></td>
|
||||
<td class="article-number">{{ group.variant.manufacturer_color_code|default:"–" }}</td>
|
||||
<td><span class="badge">{{ group.variant.get_spool_type_display }}</span>{% if not group.variant.is_active %}<small class="warning">Deaktiviert · bestehender Wunsch</small>{% endif %}</td>
|
||||
<td>{% for entry in group.entries %}<div class="person">{{ entry.owner.username }}: <strong>{{ entry.quantity }}</strong>{% if entry.owner_id == user.pk %}<span class="actions"> · <a href="{% url 'order_edit' entry.pk %}">Ändern</a> · <a class="danger-link" href="{% url 'order_delete' entry.pk %}">Entfernen</a></span>{% endif %}</div>{% endfor %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody></table></div>{% else %}<div class="empty"><span class="empty-icon" aria-hidden="true">↗</span><h3>Was fehlt für dein nächstes Projekt?</h3><p>Füge deinen ersten Wunsch hinzu. Die anderen sehen ihn und können sich anschließen.</p><a class="button" href="{% url 'order_add' %}">Bestellwunsch auswählen</a></div>{% endif %}</section>{% endblock %}
|
||||
@@ -1,6 +1,6 @@
|
||||
{% 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>
|
||||
<section class="panel form-panel"><form method="post" data-catalog-form>{% csrf_token %}{{ form.non_field_errors }}
|
||||
<section class="panel form-panel variant-panel"><form method="post" data-catalog-form>{% csrf_token %}{{ form.non_field_errors }}
|
||||
<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">
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<span class="variant-thumbnail" aria-hidden="true">
|
||||
<span class="variant-thumbnail-placeholder">◉</span>
|
||||
{% if variant.image_url %}
|
||||
<img src="{{ variant.image_url }}" alt="" width="48" height="48" loading="lazy" decoding="async" referrerpolicy="no-referrer">
|
||||
{% endif %}
|
||||
</span>
|
||||
Reference in new issue
Block a user