project/scipycon/registration/forms.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 18 Nov 2010 16:16:28 +0530
branchpayments
changeset 276 325ec5a41269
parent 262 b7c39720475a
parent 272 4801b7adbbc5
child 315 566e5f783e75
permissions -rw-r--r--
Merge payments branch with the default mainline branch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
from django import forms
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
from django.core.exceptions import ObjectDoesNotExist
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     4
from project.scipycon.registration.models import SIZE_CHOICES
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     5
from project.scipycon.registration.models import OCCUPATION_CHOICES
199
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
     6
from project.scipycon.registration.models import Accommodation
249
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
     7
from project.scipycon.registration.models import Payment
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     8
from project.scipycon.registration.models import Wifi
96
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
     9
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
class RegistrationSubmitForm(forms.Form):
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    12
    """SciPyCon registration form
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
    """
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    14
    #tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=True,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    15
    #    label=u'T-shirt size', help_text=u'Yes, we all get a t-shirt!')
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
    organisation = forms.CharField(required=True, label=u'Organisation',
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
        help_text=u'The primary organisation that you are a member of.',
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
        max_length=255,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
        widget=forms.TextInput(attrs={'size':'50'}))
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    20
    occupation = forms.ChoiceField(choices=OCCUPATION_CHOICES,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    21
        required=True, label=u'Occupation',
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    22
        help_text=u'Title of your occupation')
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    23
    city = forms.CharField(required=False, label=u'City',
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    24
        help_text=u'Your city of residence',
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
        max_length=255,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
        widget=forms.TextInput(attrs={'size':'50'}))
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
    postcode = forms.CharField(required=False, label=u'Postcode',
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    28
        help_text=u'PIN Code of your area',
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
        max_length=10,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
        widget=forms.TextInput(attrs={'size':'10'}))
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    31
    phone_num = forms.CharField(required=False, label=u'Phone Number',
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    32
        help_text=u'Phone number. Although optional, please provide it for '
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    33
        'faster correspondence', max_length=14,
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    34
        widget=forms.TextInput(attrs={'size':'20'}))
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
    allow_contact = forms.BooleanField(required=False, label=u'Contact',
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
        help_text=u'May organizers of SciPy.in contact you after the event?')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
    conference = forms.BooleanField(required=False, label=u'Conference',
191
0eb941d14ec3 Changing the fee details in the registration form to the link.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 137
diff changeset
    38
        help_text=u"""Do you intend to attend SciPy.in 2010 conference?""")
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
    tutorial = forms.BooleanField(required=False, label=u'Tutorial',
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
        help_text=u'Do you intend to attend the tutorials?')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
    sprint = forms.BooleanField(required=False, label=u'Sprint',
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
        help_text=u'Do you intend to attend the sprints?')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    44
    def occupation_fields(self):
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
        return (self['organisation'],
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    46
                self['occupation'])
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    47
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    48
    def demographic_fields(self):
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    49
        return (self['city'],
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    50
                self['postcode'],
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    51
                self['phone_num'])
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    def personal_fields(self):
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    54
        return (#self['tshirt'],
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
                self['conference'],
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
                self['tutorial'],
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
                self['sprint'],
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
                self['allow_contact'])
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
class RegistrationEditForm(RegistrationSubmitForm):
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
    id = forms.CharField(widget=forms.HiddenInput)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
class WifiForm(forms.ModelForm):
246
1bd29275df1f Change docstring for form classes form PyCON to SciPyCON.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 199
diff changeset
    65
    """SciPyCon wifi form
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
    """
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    68
    def save(self, user, scope):
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    69
        try:
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    70
            wifi = Wifi.objects.get(user=user, scope=scope)
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    71
        except ObjectDoesNotExist:
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    72
            wifi = Wifi(user=user, scope=scope)
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    73
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    74
        wifi.wifi = self.cleaned_data['wifi']
272
4801b7adbbc5 Add registration_id field to Wifi model and make necessary changes in the form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 199
diff changeset
    75
        wifi.registration_id = self.cleaned_data['registration_id']
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
        wifi.save()
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    77
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
        return wifi
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
    class Meta:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
        model = Wifi
272
4801b7adbbc5 Add registration_id field to Wifi model and make necessary changes in the form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 199
diff changeset
    82
        fields = ('wifi', 'registration_id')
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
199
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    84
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    85
class AccommodationForm(forms.ModelForm):
246
1bd29275df1f Change docstring for form classes form PyCON to SciPyCON.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 199
diff changeset
    86
    """SciPyCon Accommodation form
199
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    87
    """
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    88
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    89
    def save(self, user, scope):
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    90
        try:
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    91
            acco = Accommodation.objects.get(user=user, scope=scope)
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    92
        except ObjectDoesNotExist:
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    93
            acco = Accommodation(user=user, scope=scope)
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    94
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    95
        sex = self.cleaned_data['sex']
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    96
        accommodation_required = self.cleaned_data['accommodation_required']
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    97
        accommodation_days = self.cleaned_data['accommodation_days']
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    98
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
    99
        acco.sex = sex
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   100
        acco.accommodation_required = accommodation_required
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   101
        acco.accommodation_days = accommodation_days if (
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   102
            accommodation_days) else 0
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   103
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   104
        acco.save()
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   105
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   106
        return acco
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   107
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   108
    def clean(self):
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   109
        """Makes sure that accommodation form is correct, i.e. sex
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   110
        and number of days required are filled in when the accommodation
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   111
        is required.
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   112
        """
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   113
        cleaned = self.cleaned_data
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   114
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   115
        sex = self.cleaned_data['sex']
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   116
        accommodation_required = self.cleaned_data['accommodation_required']
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   117
        accommodation_days = self.cleaned_data['accommodation_days']
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   118
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   119
        if accommodation_required and (not sex or not accommodation_days
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   120
            or accommodation_days == 0):
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   121
            raise forms.ValidationError(
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   122
                u"If accommodation is required both gender and number of "
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   123
                "days for which accommodation is required is mandatory.")
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   124
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   125
        return super(AccommodationForm, self).clean()
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   126
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   127
    class Meta:
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   128
        model = Accommodation
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   129
        fields = ('accommodation_required', 'sex', 'accommodation_days')
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   130
97cbeda302a9 Added accommodation Django form, wrote the save method and overwrote the cleaner.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 191
diff changeset
   131
249
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   132
class PaymentForm(forms.ModelForm):
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   133
    """SciPyCon Payment form
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   134
    """
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   135
262
b7c39720475a Remove the paid field from model form since it is now a dummy form field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 261
diff changeset
   136
    paid = forms.BooleanField(
b7c39720475a Remove the paid field from model form since it is now a dummy form field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 261
diff changeset
   137
        required=False, label="Amount paid",
b7c39720475a Remove the paid field from model form since it is now a dummy form field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 261
diff changeset
   138
        help_text="Check this box if you have already paid the fees.")
b7c39720475a Remove the paid field from model form since it is now a dummy form field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 261
diff changeset
   139
249
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   140
    def save(self, user, scope):
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   141
        try:
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   142
            payment = Payment.objects.get(user=user, scope=scope)
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   143
        except ObjectDoesNotExist:
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   144
            payment = Payment(user=user, scope=scope)
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   145
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   146
        paid = self.cleaned_data['paid']
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   147
        type = self.cleaned_data['type']
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   148
        details = self.cleaned_data['details']
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   149
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   150
        payment.type = type
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   151
        payment.details = details
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   152
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   153
        payment.save()
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   154
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   155
        return payment
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   156
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   157
    def clean(self):
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   158
        """Makes sure that payment form is correct, i.e. type and details
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   159
        are filled in when the required fees is paid.
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   160
        """
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   161
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   162
        paid = self.cleaned_data['paid']
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   163
        type = self.cleaned_data['type']
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   164
        details = self.cleaned_data['details']
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   165
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   166
        if paid and (not type or not details):
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   167
            raise forms.ValidationError(
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   168
                u"If you have already paid the fee it is mandatory to "
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   169
                "fill in the type and mandatory fields.")
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   170
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   171
        return super(PaymentForm, self).clean()
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   172
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   173
    class Meta:
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   174
        model = Payment
261
148f277e7db2 Typo of type field twice is fixed to details field in the form of registrantion.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 249
diff changeset
   175
        fields = ('paid', 'type', 'details')
249
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   176
9d90fbae1216 Add a form for Payment and respective save and clean methods.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 246
diff changeset
   177
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
PC = (
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
        ('all', 'all'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
        ('paid', 'paid'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
        ('not paid', 'not paid')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
        )
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
HC = (
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
        ('all', 'all'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
        ('party', 'party'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
        ('no party', 'no party')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
        )
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
AC = (
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
        ('all', 'all'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
        ('0', '0'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
        ('10', '10'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
        ('20', '20'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
        ('40', '40'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
        )
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
OC = (
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
        ('email', 'email'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
        ('amount', 'amount'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
        )
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
IC = (
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
        ('Name', 'name'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
        ('Email', 'email'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
        ('Amount', 'amount'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
        ('Organisation', 'organisation'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
        ('Conference', 'conference'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
        ('Tutorial', 'tutorial'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
        ('Sprint', 'sprint'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
        ('T-size', 'tshirt'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
        )
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   211
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
class RegistrationAdminSelectForm(forms.Form):
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
    """
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
    Used to make selection for csv download
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
    """
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
    by_payment = forms.ChoiceField(choices=PC, required=False,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
        label=u'By payment')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
    by_amount = forms.MultipleChoiceField(choices=AC, required=False,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
        label=u'By amount')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
    by_party = forms.ChoiceField(choices=HC, required=False,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
        label=u'by party')
137
ec6e58c639bf Added phone number, modified Occupation to be choice field.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   222
    by_tshirt = forms.ChoiceField(choices=SIZE_CHOICES, required=False,
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
        label=u'by tshirt size')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
    order_by = forms.ChoiceField(choices=OC, required=False,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
        label=u'order results')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
    include = forms.MultipleChoiceField(choices=IC, required=False,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
        label=u'Include fields')