Coverage for website/sales/forms.py: 34.78%
19 statements
« prev ^ index » next coverage.py v7.6.12, created at 2026-06-21 23:59 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2026-06-21 23:59 +0000
1from django import forms
3from sales.models.product import ProductListItem
6class ProductItemField(forms.IntegerField):
7 def get_productlistitem(self):
8 return self._productlistitem
10 def get_product(self):
11 return self._productlistitem.product
13 def set_productlistitem(self, product_list_item):
14 self._productlistitem = product_list_item
17class ProductOrderForm(forms.Form):
18 def __init__(self, product_list, is_adult, *args, **kwargs):
19 super().__init__(*args, **kwargs)
20 product_list_items = ProductListItem.objects.filter(product_list=product_list)
21 for item in product_list_items:
22 field = ProductItemField(
23 label=item.product.name,
24 required=False,
25 min_value=0,
26 )
27 field.set_productlistitem(item)
28 if not is_adult and item.product.age_restricted:
29 field.disabled = True
30 self.fields[f"product_{item.product.pk}"] = field