2 from django.core.exceptions import ObjectDoesNotExist |
2 from django.core.exceptions import ObjectDoesNotExist |
3 |
3 |
4 from project.scipycon.registration.models import SIZE_CHOICES |
4 from project.scipycon.registration.models import SIZE_CHOICES |
5 from project.scipycon.registration.models import OCCUPATION_CHOICES |
5 from project.scipycon.registration.models import OCCUPATION_CHOICES |
6 from project.scipycon.registration.models import Accommodation |
6 from project.scipycon.registration.models import Accommodation |
|
7 from project.scipycon.registration.models import Payment |
7 from project.scipycon.registration.models import Wifi |
8 from project.scipycon.registration.models import Wifi |
8 |
9 |
9 |
10 |
10 class RegistrationSubmitForm(forms.Form): |
11 class RegistrationSubmitForm(forms.Form): |
11 """SciPyCon registration form |
12 """SciPyCon registration form |
125 class Meta: |
126 class Meta: |
126 model = Accommodation |
127 model = Accommodation |
127 fields = ('accommodation_required', 'sex', 'accommodation_days') |
128 fields = ('accommodation_required', 'sex', 'accommodation_days') |
128 |
129 |
129 |
130 |
|
131 class PaymentForm(forms.ModelForm): |
|
132 """SciPyCon Payment form |
|
133 """ |
|
134 |
|
135 def save(self, user, scope): |
|
136 try: |
|
137 payment = Payment.objects.get(user=user, scope=scope) |
|
138 except ObjectDoesNotExist: |
|
139 payment = Payment(user=user, scope=scope) |
|
140 |
|
141 paid = self.cleaned_data['paid'] |
|
142 type = self.cleaned_data['type'] |
|
143 details = self.cleaned_data['details'] |
|
144 |
|
145 payment.paid = paid |
|
146 payment.type = type |
|
147 payment.details = details |
|
148 |
|
149 payment.save() |
|
150 |
|
151 return payment |
|
152 |
|
153 def clean(self): |
|
154 """Makes sure that payment form is correct, i.e. type and details |
|
155 are filled in when the required fees is paid. |
|
156 """ |
|
157 |
|
158 paid = self.cleaned_data['paid'] |
|
159 type = self.cleaned_data['type'] |
|
160 details = self.cleaned_data['details'] |
|
161 |
|
162 if paid and (not type or not details): |
|
163 raise forms.ValidationError( |
|
164 u"If you have already paid the fee it is mandatory to " |
|
165 "fill in the type and mandatory fields.") |
|
166 |
|
167 return super(PaymentForm, self).clean() |
|
168 |
|
169 class Meta: |
|
170 model = Payment |
|
171 fields = ('paid', 'type', 'type') |
|
172 |
|
173 |
130 PC = ( |
174 PC = ( |
131 ('all', 'all'), |
175 ('all', 'all'), |
132 ('paid', 'paid'), |
176 ('paid', 'paid'), |
133 ('not paid', 'not paid') |
177 ('not paid', 'not paid') |
134 ) |
178 ) |