Add filament previews, article numbers and admin feedback

This commit is contained in:
Mikei386 committed 2026-11-14 15:08:34 +01:00
1 parent 7b56a0e3ef
commit 40d6843147
23 files changed
+1334 -17

No files matched your search

+26 -2
View File
@@ -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