project/kiwipycon/registration/forms.py
changeset 94 87e77aa18610
parent 93 e86755df35da
child 95 f94e0cd9a862
equal deleted inserted replaced
93:e86755df35da 94:87e77aa18610
     1 # -*- coding: utf-8 -*-
       
     2 from __future__ import absolute_import
       
     3 
       
     4 #django
       
     5 from django import forms
       
     6 from django.core.exceptions import ObjectDoesNotExist
       
     7 
       
     8 #django.contrib
       
     9 from django.contrib.auth.models import User
       
    10 
       
    11 from .models import SIZE_CHOICES
       
    12 from .models import Registration
       
    13 from .models import Wifi
       
    14 from project.kiwipycon.sponsor.models import Sponsor
       
    15 
       
    16 class RegistrationSubmitForm(forms.Form):
       
    17     """PyCon registration form
       
    18     """
       
    19     tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=True,
       
    20         label=u'T-shirt size', help_text=u'Yes, we all get a t-shirt!')
       
    21 #    beverage = forms.CharField(required=True, label=u'Beverage',
       
    22 #        help_text=u'Your beverage of choice - coffee, tea etc',
       
    23 #        max_length=255,
       
    24 #        widget=forms.TextInput(attrs={'size':'50'}))
       
    25 #    diet = forms.CharField(required=False, label=u'Dietary',
       
    26 #        help_text=u'Special dietary requirements - vegetarian etc',
       
    27 #        max_length=255,
       
    28 #        widget=forms.TextInput(attrs={'size':'50'}))
       
    29     organisation = forms.CharField(required=True, label=u'Organisation',
       
    30         help_text=u'The primary organisation that you are a member of.',
       
    31         max_length=255,
       
    32         widget=forms.TextInput(attrs={'size':'50'}))
       
    33     occupation = forms.CharField(required=True, label=u'Occupation',
       
    34         help_text=u'Title of your occupation',
       
    35         max_length=255,
       
    36         widget=forms.TextInput(attrs={'size':'50'}))
       
    37     city = forms.CharField(required=True, label=u'City',
       
    38         help_text=u'City of residence',
       
    39         max_length=255,
       
    40         widget=forms.TextInput(attrs={'size':'50'}))
       
    41     postcode = forms.CharField(required=False, label=u'Postcode',
       
    42         help_text=u'This field is optional',
       
    43         max_length=10,
       
    44         widget=forms.TextInput(attrs={'size':'10'}))
       
    45     allow_contact = forms.BooleanField(required=False, label=u'Contact',
       
    46         help_text=u'May organizers of SciPy.in contact you after the event?')
       
    47     conference = forms.BooleanField(required=False, label=u'Conference',
       
    48         help_text=u"""Do you intend to attend the SciPy conference?  
       
    49         Note: Only conference has an registration fee of Rs.200 which you will
       
    50         pay on the spot.""")
       
    51     tutorial = forms.BooleanField(required=False, label=u'Tutorial',
       
    52         help_text=u'Do you intend to attend the tutorials?')
       
    53     sprint = forms.BooleanField(required=False, label=u'Sprint',
       
    54         help_text=u'Do you intend to attend the sprints?')
       
    55 #    party = forms.BooleanField(required=False, label=u'Pre-con party',
       
    56 #        help_text=u'Do you intend to attend the pre-conference party on Friday?')
       
    57 #    discount = forms.BooleanField(required=False, label=u'Student/Unwaged?',
       
    58 #        help_text=u'You will be required to present your Community Services '\
       
    59 #                'Card or Student ID on arrival.')
       
    60 #    sponsor = forms.CharField(required=False, label=u'Sponsor code',
       
    61 #        help_text=u'If attending as a sponsor please enter your sponsor code.',
       
    62 #        max_length=50,
       
    63 #        widget=forms.TextInput(attrs={'size':'20'}))
       
    64 
       
    65     def demographic_fields(self):
       
    66         return (self['organisation'],
       
    67                 self['occupation'],
       
    68                 self['city'],
       
    69                 self['postcode'])
       
    70 
       
    71     def personal_fields(self):
       
    72         return (self['tshirt'],
       
    73                 self['conference'],
       
    74                 self['tutorial'],
       
    75                 self['sprint'],
       
    76                 self['allow_contact'])
       
    77 
       
    78 #    def other_fields(self):
       
    79 #        return (self['sponsor'],)
       
    80 #
       
    81 #    def clean_sponsor(self):
       
    82 #        """Validates that the entered sponsor code is valid and within limits
       
    83 #        of allowed guests
       
    84 #        """
       
    85 #        sponsorcode = self.cleaned_data.get("sponsor")
       
    86 #        if sponsorcode:
       
    87 #            try:
       
    88 #                sponsor = Sponsor.objects.get(slug=sponsorcode)
       
    89 #            except ObjectDoesNotExist:
       
    90 #                raise forms.ValidationError(
       
    91 #                    u"The sponsor code you entered is not valid.")
       
    92 #            if sponsor:
       
    93 #                guests = sponsor.guests
       
    94 #                if guests == 0:
       
    95 #                    raise forms.ValidationError(
       
    96 #                        u"The sponsor code you entered is not valid.")
       
    97 #                count = Registration.objects.filter(
       
    98 #                            sponsor=sponsorcode).count()
       
    99 #                if count >= guests:
       
   100 #                    raise forms.ValidationError(
       
   101 #                    u"That sponsor has reached limit of guests.")
       
   102 #
       
   103 #
       
   104 #        return sponsorcode
       
   105 
       
   106 
       
   107 class RegistrationEditForm(RegistrationSubmitForm):
       
   108     id = forms.CharField(widget=forms.HiddenInput)
       
   109     sponsor = forms.CharField(required=False, widget=forms.HiddenInput)
       
   110 
       
   111 class WifiForm(forms.ModelForm):
       
   112     """PyCon wifi form
       
   113     """
       
   114 
       
   115     def save(self, user):
       
   116         wifi = Wifi(user=user, wifi=self.cleaned_data['wifi'])
       
   117         wifi.save()
       
   118         return wifi
       
   119 
       
   120     class Meta:
       
   121         model = Wifi
       
   122         fields = ('wifi',)
       
   123 
       
   124 PC = (
       
   125         ('all', 'all'),
       
   126         ('paid', 'paid'),
       
   127         ('not paid', 'not paid')
       
   128         )
       
   129 HC = (
       
   130         ('all', 'all'),
       
   131         ('party', 'party'),
       
   132         ('no party', 'no party')
       
   133         )
       
   134 AC = (
       
   135         ('all', 'all'),
       
   136         ('0', '0'),
       
   137         ('10', '10'),
       
   138         ('20', '20'),
       
   139         ('40', '40'),
       
   140         )
       
   141 OC = (
       
   142         ('email', 'email'),
       
   143         ('amount', 'amount'),
       
   144         )
       
   145 
       
   146 IC = (
       
   147         ('Name', 'name'),
       
   148         ('Email', 'email'),
       
   149         ('Amount', 'amount'),
       
   150         ('Organisation', 'organisation'),
       
   151         ('Conference', 'conference'),
       
   152         ('Tutorial', 'tutorial'),
       
   153         ('Sprint', 'sprint'),
       
   154         ('T-size', 'tshirt'),
       
   155         )
       
   156 
       
   157 SC = (
       
   158     ('all', 'all'),
       
   159     ('S', 'S'),
       
   160     ('M', 'M'),
       
   161     ('L', 'L'),
       
   162     ('XL', 'XL'),
       
   163     )
       
   164 class RegistrationAdminSelectForm(forms.Form):
       
   165     """
       
   166     Used to make selection for csv download
       
   167     """
       
   168     by_payment = forms.ChoiceField(choices=PC, required=False,
       
   169         label=u'By payment')
       
   170     by_amount = forms.MultipleChoiceField(choices=AC, required=False,
       
   171         label=u'By amount')
       
   172     by_party = forms.ChoiceField(choices=HC, required=False,
       
   173         label=u'by party')
       
   174     by_tshirt = forms.ChoiceField(choices=SC, required=False,
       
   175         label=u'by tshirt size')
       
   176     order_by = forms.ChoiceField(choices=OC, required=False,
       
   177         label=u'order results')
       
   178     include = forms.MultipleChoiceField(choices=IC, required=False,
       
   179         label=u'Include fields')