10 |
10 |
11 from project.scipycon.base.models import Event |
11 from project.scipycon.base.models import Event |
12 from project.scipycon.registration.forms import RegistrationEditForm |
12 from project.scipycon.registration.forms import RegistrationEditForm |
13 from project.scipycon.registration.forms import RegistrationSubmitForm |
13 from project.scipycon.registration.forms import RegistrationSubmitForm |
14 from project.scipycon.registration.forms import AccommodationForm |
14 from project.scipycon.registration.forms import AccommodationForm |
|
15 from project.scipycon.registration.forms import PaymentForm |
15 from project.scipycon.registration.forms import WifiForm |
16 from project.scipycon.registration.forms import WifiForm |
16 from project.scipycon.registration.models import Accommodation |
17 from project.scipycon.registration.models import Accommodation |
|
18 from project.scipycon.registration.models import Payment |
17 from project.scipycon.registration.models import Registration |
19 from project.scipycon.registration.models import Registration |
18 from project.scipycon.registration.models import Wifi |
20 from project.scipycon.registration.models import Wifi |
19 from project.scipycon.registration.utils import send_confirmation |
21 from project.scipycon.registration.utils import send_confirmation |
20 from project.scipycon.user.forms import RegistrantForm |
22 from project.scipycon.user.forms import RegistrantForm |
21 from project.scipycon.user.models import UserProfile |
23 from project.scipycon.user.models import UserProfile |
57 scope_entity = Event.objects.get(scope=scope) |
59 scope_entity = Event.objects.get(scope=scope) |
58 |
60 |
59 reg = Registration.objects.get(pk=id) |
61 reg = Registration.objects.get(pk=id) |
60 wifi = Wifi.objects.get(user=reg.registrant) |
62 wifi = Wifi.objects.get(user=reg.registrant) |
61 |
63 |
62 # TODO: This is an ugly hack to add accommodation form |
64 # TODO: This is an ugly hack to add accommodation and payment forms |
63 # details at later stage for SciPy.in 2010. This must be |
65 # details at later stage for SciPy.in 2010. This must be removed for |
64 # removed for SciPy.in 2011 |
66 # SciPy.in 2011 |
65 acco, acco_created = Accommodation.objects.get_or_create( |
67 acco, acco_created = Accommodation.objects.get_or_create( |
|
68 user=reg.registrant, scope=scope_entity) |
|
69 payment, payment_created = Payment.objects.get_or_create( |
66 user=reg.registrant, scope=scope_entity) |
70 user=reg.registrant, scope=scope_entity) |
67 |
71 |
68 if reg.registrant != request.user: |
72 if reg.registrant != request.user: |
69 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
73 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
70 |
74 |
75 |
79 |
76 if request.method == 'POST': |
80 if request.method == 'POST': |
77 registration_form = RegistrationEditForm(data=request.POST) |
81 registration_form = RegistrationEditForm(data=request.POST) |
78 wifi_form = WifiForm(data=request.POST) |
82 wifi_form = WifiForm(data=request.POST) |
79 acco_form = AccommodationForm(data=request.POST) |
83 acco_form = AccommodationForm(data=request.POST) |
|
84 payment_form = PaymentForm(data=request.POST) |
80 |
85 |
81 if (registration_form.is_valid() and wifi_form.is_valid() and |
86 if (registration_form.is_valid() and wifi_form.is_valid() and |
82 acco_form.is_valid()): |
87 acco_form.is_valid() and payment_form.is_valid()): |
83 reg.organisation = registration_form.data.get('organisation') |
88 reg.organisation = registration_form.data.get('organisation') |
84 reg.occupation = registration_form.data.get('occupation') |
89 reg.occupation = registration_form.data.get('occupation') |
85 reg.city = registration_form.data.get('city') |
90 reg.city = registration_form.data.get('city') |
86 reg.phone_num = registration_form.data.get('phone_num') |
91 reg.phone_num = registration_form.data.get('phone_num') |
87 reg.postcode = registration_form.data.get('postcode') |
92 reg.postcode = registration_form.data.get('postcode') |
96 'sprint') and True or False |
101 'sprint') and True or False |
97 reg.save() |
102 reg.save() |
98 |
103 |
99 wifi = wifi_form.save(reg.registrant, reg.scope) |
104 wifi = wifi_form.save(reg.registrant, reg.scope) |
100 acco = acco_form.save(reg.registrant, reg.scope) |
105 acco = acco_form.save(reg.registrant, reg.scope) |
|
106 payment = payment_form.save(reg.registrant, reg.scope) |
101 |
107 |
102 # Saved.. redirect |
108 # Saved.. redirect |
103 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
109 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
104 |
110 |
105 return set_message_cookie(redirect_to, |
111 return set_message_cookie(redirect_to, |
128 'scope': acco.scope, |
134 'scope': acco.scope, |
129 'sex': acco.sex, |
135 'sex': acco.sex, |
130 'accommodation_required': acco.accommodation_required, |
136 'accommodation_required': acco.accommodation_required, |
131 'accommodation_days': acco.accommodation_days, |
137 'accommodation_days': acco.accommodation_days, |
132 }) |
138 }) |
|
139 payment_form = PaymentForm(initial={ |
|
140 'user': payment.user, |
|
141 'scope': payment.scope, |
|
142 'paid': payment.paid, |
|
143 'type': payment.type, |
|
144 'details': payment.details, |
|
145 }) |
133 |
146 |
134 return render_to_response( |
147 return render_to_response( |
135 template_name, RequestContext(request, { |
148 template_name, RequestContext(request, { |
136 'params': {'scope': scope}, |
149 'params': {'scope': scope}, |
137 'registration': {'id': id}, |
150 'registration': {'id': id}, |
138 'registration_form': registration_form, |
151 'registration_form': registration_form, |
139 'wifi_form': wifi_form, |
152 'wifi_form': wifi_form, |
140 'acco_form': acco_form})) |
153 'acco_form': acco_form, |
|
154 'payment_form': payment_form})) |
141 |
155 |
142 def submit_registration(request, scope, |
156 def submit_registration(request, scope, |
143 template_name='registration/submit-registration.html'): |
157 template_name='registration/submit-registration.html'): |
144 """Allows user to edit registration |
158 """Allows user to edit registration |
145 """ |
159 """ |
173 if request.method == 'POST': |
187 if request.method == 'POST': |
174 registration_form = RegistrationSubmitForm(data=request.POST) |
188 registration_form = RegistrationSubmitForm(data=request.POST) |
175 registrant_form = RegistrantForm(data=request.POST) |
189 registrant_form = RegistrantForm(data=request.POST) |
176 wifi_form = WifiForm(data=request.POST) |
190 wifi_form = WifiForm(data=request.POST) |
177 acco_form = AccommodationForm(data=request.POST) |
191 acco_form = AccommodationForm(data=request.POST) |
|
192 payment_form = PaymentForm(data=request.POST) |
178 |
193 |
179 if request.POST.get('action', None) == 'login': |
194 if request.POST.get('action', None) == 'login': |
180 login_form = AuthenticationForm(data=request.POST) |
195 login_form = AuthenticationForm(data=request.POST) |
181 if login_form.is_valid(): |
196 if login_form.is_valid(): |
182 |
197 |
208 |
223 |
209 else: |
224 else: |
210 newuser = user |
225 newuser = user |
211 |
226 |
212 if (registration_form.is_valid() and newuser and wifi_form.is_valid() |
227 if (registration_form.is_valid() and newuser and wifi_form.is_valid() |
213 and acco_form.is_valid()): |
228 and acco_form.is_valid() and payment_form.is_valid()): |
214 allow_contact = registration_form.cleaned_data.get( |
229 allow_contact = registration_form.cleaned_data.get( |
215 'allow_contact') and True or False |
230 'allow_contact') and True or False |
216 conference = registration_form.cleaned_data.get( |
231 conference = registration_form.cleaned_data.get( |
217 'conference') and True or False |
232 'conference') and True or False |
218 tutorial = registration_form.cleaned_data.get('tutorial') and \ |
233 tutorial = registration_form.cleaned_data.get('tutorial') and \ |
244 reg.slug = slug |
259 reg.slug = slug |
245 reg.save() |
260 reg.save() |
246 |
261 |
247 wifi = wifi_form.save(registrant, scope_entity) |
262 wifi = wifi_form.save(registrant, scope_entity) |
248 acco = acco_form.save(registrant, scope_entity) |
263 acco = acco_form.save(registrant, scope_entity) |
|
264 payment = payment_form.save(registrant, scope_entity) |
249 |
265 |
250 send_confirmation(registrant, scope_entity,password=passwd) |
266 send_confirmation(registrant, scope_entity,password=passwd) |
251 |
267 |
252 redirect_to = reverse('scipycon_registrations', |
268 redirect_to = reverse('scipycon_registrations', |
253 kwargs={'scope': scope}) |
269 kwargs={'scope': scope}) |
258 else: |
274 else: |
259 registration_form = RegistrationSubmitForm() |
275 registration_form = RegistrationSubmitForm() |
260 registrant_form = RegistrantForm() |
276 registrant_form = RegistrantForm() |
261 wifi_form = WifiForm() |
277 wifi_form = WifiForm() |
262 acco_form = AccommodationForm() |
278 acco_form = AccommodationForm() |
|
279 payment_form = PaymentForm() |
263 |
280 |
264 login_form = AuthenticationForm() |
281 login_form = AuthenticationForm() |
265 |
282 |
266 |
283 |
267 return render_to_response(template_name, RequestContext(request, { |
284 return render_to_response(template_name, RequestContext(request, { |
268 'params': {'scope': scope}, |
285 'params': {'scope': scope}, |
269 'registration_form': registration_form, |
286 'registration_form': registration_form, |
270 'registrant_form' : registrant_form, |
287 'registrant_form' : registrant_form, |
271 'over_reg' : reg_count >= REG_TOTAL and True or False, |
288 'over_reg' : reg_count >= REG_TOTAL and True or False, |
272 'acco_form': acco_form, |
289 'acco_form': acco_form, |
|
290 'payment_form': payment_form, |
273 'wifi_form' : wifi_form, |
291 'wifi_form' : wifi_form, |
274 'message' : message, |
292 'message' : message, |
275 'login_form' : login_form |
293 'login_form' : login_form |
276 })) |
294 })) |
277 |
295 |