Files
@ c41a9cadffb9
Branch filter:
Location: symposion_app/registrasion/forms.py - annotation
c41a9cadffb9
2.2 KiB
text/x-python
recalculate_discounts now uses the available_discounts function from controllers.discount.
1b7d8a60c119 1b7d8a60c119 7086ea87292d 7086ea87292d 1b7d8a60c119 1b7d8a60c119 1b7d8a60c119 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 7086ea87292d 7086ea87292d 7086ea87292d 7086ea87292d 7086ea87292d 7086ea87292d 7086ea87292d 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 745f6db444fa 2d6b28c5a6da 236c61eefa0d 236c61eefa0d 236c61eefa0d 236c61eefa0d 236c61eefa0d 236c61eefa0d 236c61eefa0d 236c61eefa0d 236c61eefa0d 2d6b28c5a6da 2d6b28c5a6da 2d6b28c5a6da 2d6b28c5a6da d50d6bac482c 2d6b28c5a6da | import models as rego
from controllers.product import ProductController
from django import forms
def CategoryForm(category):
PREFIX = "product_"
def field_name(product):
return PREFIX + ("%d" % product.id)
class _CategoryForm(forms.Form):
@staticmethod
def initial_data(product_quantities):
''' Prepares initial data for an instance of this form.
product_quantities is a sequence of (product,quantity) tuples '''
initial = {}
for product, quantity in product_quantities:
initial[field_name(product)] = quantity
return initial
def product_quantities(self):
''' Yields a sequence of (product, quantity) tuples from the
cleaned form data. '''
for name, value in self.cleaned_data.items():
if name.startswith(PREFIX):
product_id = int(name[len(PREFIX):])
yield (product_id, value, name)
def disable_product(self, product):
''' Removes a given product from this form. '''
del self.fields[field_name(product)]
def disable_products_for_user(self, user):
for product in products:
# Remove fields that do not have an enabling condition.
prod = ProductController(product)
if not prod.can_add_with_enabling_conditions(user, 0):
self.disable_product(product)
products = rego.Product.objects.filter(category=category).order_by("order")
for product in products:
help_text = "$%d -- %s" % (product.price, product.description)
field = forms.IntegerField(
label=product.name,
help_text=help_text,
)
_CategoryForm.base_fields[field_name(product)] = field
return _CategoryForm
class ProfileForm(forms.ModelForm):
''' A form for requesting badge and profile information. '''
class Meta:
model = rego.BadgeAndProfile
exclude = ['attendee']
class VoucherForm(forms.Form):
voucher = forms.CharField(
label="Voucher code",
help_text="If you have a voucher code, enter it here",
required=False,
)
|