92 except ObjectDoesNotExist: |
92 except ObjectDoesNotExist: |
93 acco = Accommodation(user=user, scope=scope) |
93 acco = Accommodation(user=user, scope=scope) |
94 |
94 |
95 sex = self.cleaned_data['sex'] |
95 sex = self.cleaned_data['sex'] |
96 accommodation_required = self.cleaned_data['accommodation_required'] |
96 accommodation_required = self.cleaned_data['accommodation_required'] |
97 accommodation_days = self.cleaned_data['accommodation_days'] |
97 accommodation_days = sum(filter([a1, a2, a3, a4, a5, a6])) |
|
98 |
|
99 a1 = self.cleaned_data['accomodation_on_1st'] |
|
100 a2 = self.cleaned_data['accomodation_on_2nd'] |
|
101 a3 = self.cleaned_data['accomodation_on_3rd'] |
|
102 a4 = self.cleaned_data['accomodation_on_4th'] |
|
103 a5 = self.cleaned_data['accomodation_on_5th'] |
|
104 a6 = self.cleaned_data['accomodation_on_6th'] |
98 |
105 |
99 acco.sex = sex |
106 acco.sex = sex |
100 acco.accommodation_required = accommodation_required |
107 acco.accommodation_required = accommodation_required |
101 acco.accommodation_days = accommodation_days if ( |
108 acco.accommodation_days = accomodation_days |
102 accommodation_days) else 0 |
109 |
|
110 acco.accomodation_on_1st = a1 |
|
111 acco.accomodation_on_2nd = a2 |
|
112 acco.accomodation_on_3rd = a3 |
|
113 acco.accomodation_on_4th = a4 |
|
114 acco.accomodation_on_5th = a5 |
|
115 acco.accomodation_on_6th = a6 |
|
116 |
103 |
117 |
104 acco.save() |
118 acco.save() |
105 |
119 |
106 return acco |
120 return acco |
107 |
121 |
112 """ |
126 """ |
113 cleaned = self.cleaned_data |
127 cleaned = self.cleaned_data |
114 |
128 |
115 sex = self.cleaned_data['sex'] |
129 sex = self.cleaned_data['sex'] |
116 accommodation_required = self.cleaned_data['accommodation_required'] |
130 accommodation_required = self.cleaned_data['accommodation_required'] |
117 accommodation_days = self.cleaned_data['accommodation_days'] |
131 |
118 |
132 a1 = self.cleaned_data['accomodation_on_1st'] |
119 if accommodation_required and (not sex or not accommodation_days |
133 a2 = self.cleaned_data['accomodation_on_2nd'] |
120 or accommodation_days == 0): |
134 a3 = self.cleaned_data['accomodation_on_3rd'] |
|
135 a4 = self.cleaned_data['accomodation_on_4th'] |
|
136 a5 = self.cleaned_data['accomodation_on_5th'] |
|
137 a6 = self.cleaned_data['accomodation_on_6th'] |
|
138 |
|
139 selected_a_date = any([a1, a2, a3, a4, a5, a6]) |
|
140 |
|
141 if accommodation_required and (not sex or not selected_a_date): |
|
142 #or accommodation_days == 0): |
121 raise forms.ValidationError( |
143 raise forms.ValidationError( |
122 u"If accommodation is required both gender and number of " |
144 u"If accommodation is required please specify gender and" |
123 "days for which accommodation is required is mandatory.") |
145 " select the days number for which accommodation is required.") |
124 |
146 |
125 return super(AccommodationForm, self).clean() |
147 return super(AccommodationForm, self).clean() |
126 |
148 |
127 class Meta: |
149 class Meta: |
128 model = Accommodation |
150 model = Accommodation |
129 fields = ('accommodation_required', 'sex', 'accommodation_days') |
151 fields = ('accommodation_required', |
|
152 'sex', |
|
153 'accomodation_on_1st', |
|
154 'accomodation_on_2nd', |
|
155 'accomodation_on_3rd', |
|
156 'accomodation_on_4th', |
|
157 'accomodation_on_5th', |
|
158 'accomodation_on_6th', |
|
159 ) |
130 |
160 |
131 |
161 |
132 class PaymentForm(forms.ModelForm): |
162 class PaymentForm(forms.ModelForm): |
133 """SciPyCon Payment form |
163 """SciPyCon Payment form |
134 """ |
164 """ |