2016-09-20 00:33:43 +00:00
|
|
|
from registrasion.models import conditions
|
2016-09-02 04:33:23 +00:00
|
|
|
from registrasion.models import inventory
|
|
|
|
|
2016-09-20 09:18:09 +00:00
|
|
|
from symposion.proposals import models as proposals_models
|
|
|
|
|
2016-09-02 04:33:23 +00:00
|
|
|
from django import forms
|
|
|
|
|
2016-09-20 00:33:43 +00:00
|
|
|
# Reporting forms.
|
|
|
|
|
|
|
|
|
2016-10-05 18:08:58 +00:00
|
|
|
def mix_form(*a):
|
|
|
|
''' Creates a new form class out of all the supplied forms '''
|
|
|
|
|
|
|
|
bases = tuple(a)
|
|
|
|
return type("MixForm", bases, {})
|
|
|
|
|
|
|
|
|
2016-09-20 00:33:43 +00:00
|
|
|
class DiscountForm(forms.Form):
|
2017-04-24 13:05:45 +00:00
|
|
|
|
|
|
|
required_css_class = 'label-required'
|
|
|
|
|
2016-09-20 00:33:43 +00:00
|
|
|
discount = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=conditions.DiscountBase.objects.all(),
|
|
|
|
required=False,
|
|
|
|
)
|
2016-09-02 04:33:23 +00:00
|
|
|
|
2016-09-13 08:54:28 +00:00
|
|
|
|
2016-09-02 04:33:23 +00:00
|
|
|
class ProductAndCategoryForm(forms.Form):
|
2017-04-24 13:05:45 +00:00
|
|
|
|
|
|
|
required_css_class = 'label-required'
|
|
|
|
|
2016-09-02 04:33:23 +00:00
|
|
|
product = forms.ModelMultipleChoiceField(
|
2016-10-05 19:07:38 +00:00
|
|
|
queryset=inventory.Product.objects.select_related("category"),
|
2016-09-02 04:33:23 +00:00
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
category = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=inventory.Category.objects.all(),
|
|
|
|
required=False,
|
|
|
|
)
|
2016-09-02 05:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserIdForm(forms.Form):
|
2017-04-24 13:05:45 +00:00
|
|
|
|
|
|
|
required_css_class = 'label-required'
|
|
|
|
|
2016-09-02 05:15:15 +00:00
|
|
|
user = forms.IntegerField(
|
|
|
|
label="User ID",
|
|
|
|
required=False,
|
|
|
|
)
|
2016-09-20 03:36:49 +00:00
|
|
|
|
|
|
|
|
2016-09-20 09:18:09 +00:00
|
|
|
class ProposalKindForm(forms.Form):
|
2017-04-24 13:05:45 +00:00
|
|
|
|
|
|
|
required_css_class = 'label-required'
|
|
|
|
|
2016-09-20 09:18:09 +00:00
|
|
|
kind = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=proposals_models.ProposalKind.objects.all(),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-10-05 18:08:58 +00:00
|
|
|
class GroupByForm(forms.Form):
|
2017-04-24 13:05:45 +00:00
|
|
|
|
|
|
|
required_css_class = 'label-required'
|
|
|
|
|
2016-10-05 18:08:58 +00:00
|
|
|
GROUP_BY_CATEGORY = "category"
|
|
|
|
GROUP_BY_PRODUCT = "product"
|
|
|
|
|
|
|
|
choices = (
|
|
|
|
(GROUP_BY_CATEGORY, "Category"),
|
|
|
|
(GROUP_BY_PRODUCT, "Product"),
|
|
|
|
)
|
|
|
|
|
|
|
|
group_by = forms.ChoiceField(
|
|
|
|
label="Group by",
|
|
|
|
choices=choices,
|
2016-10-05 18:59:08 +00:00
|
|
|
required=False,
|
2016-10-05 18:08:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-09-20 03:36:49 +00:00
|
|
|
def model_fields_form_factory(model):
|
|
|
|
''' Creates a form for specifying fields from a model to display. '''
|
|
|
|
|
|
|
|
fields = model._meta.get_fields()
|
|
|
|
|
|
|
|
choices = []
|
|
|
|
for field in fields:
|
|
|
|
if hasattr(field, "verbose_name"):
|
|
|
|
choices.append((field.name, field.verbose_name))
|
|
|
|
|
|
|
|
class ModelFieldsForm(forms.Form):
|
|
|
|
fields = forms.MultipleChoiceField(
|
|
|
|
choices=choices,
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
return ModelFieldsForm
|