9 from django.template import RequestContext |
9 from django.template import RequestContext |
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 WifiForm |
15 from project.scipycon.registration.forms import WifiForm |
|
16 from project.scipycon.registration.models import Accommodation |
15 from project.scipycon.registration.models import Registration |
17 from project.scipycon.registration.models import Registration |
16 from project.scipycon.registration.models import Wifi |
18 from project.scipycon.registration.models import Wifi |
17 from project.scipycon.registration.utils import send_confirmation |
19 from project.scipycon.registration.utils import send_confirmation |
18 from project.scipycon.user.forms import RegistrantForm |
20 from project.scipycon.user.forms import RegistrantForm |
19 from project.scipycon.user.models import UserProfile |
21 from project.scipycon.user.models import UserProfile |
50 def edit_registration(request, scope, id, |
52 def edit_registration(request, scope, id, |
51 template_name='registration/edit-registration.html'): |
53 template_name='registration/edit-registration.html'): |
52 """Allows users that submitted a registration to edit it. |
54 """Allows users that submitted a registration to edit it. |
53 """ |
55 """ |
54 |
56 |
55 reg = Registration.objects.get(pk=id) |
57 scope_entity = Event.objects.get(scope=scope) |
|
58 |
|
59 reg = Registration.objects.get(pk=int(id)) |
56 wifi = Wifi.objects.get(user=reg.registrant) |
60 wifi = Wifi.objects.get(user=reg.registrant) |
|
61 |
|
62 # TODO: This is an ugly hack to add accommodation form |
|
63 # details at later stage for SciPy.in 2010. This must be |
|
64 # removed for SciPy.in 2011 |
|
65 acco, created = Accommodation.objects.get_or_create(user=reg.registrant, |
|
66 scope=scope_entity) |
57 |
67 |
58 if reg.registrant != request.user: |
68 if reg.registrant != request.user: |
59 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
69 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
60 |
70 |
61 return set_message_cookie( |
71 return set_message_cookie( |
64 + ' is not your own.') |
74 + ' is not your own.') |
65 |
75 |
66 if request.method == 'POST': |
76 if request.method == 'POST': |
67 registration_form = RegistrationEditForm(data=request.POST) |
77 registration_form = RegistrationEditForm(data=request.POST) |
68 wifi_form = WifiForm(data=request.POST) |
78 wifi_form = WifiForm(data=request.POST) |
69 |
79 acco_form = AccommodationForm(data=request.POST) |
70 if registration_form.is_valid() and wifi_form.is_valid(): |
80 |
|
81 if (registration_form.is_valid() and wifi_form.is_valid() and |
|
82 acco_form.is_valid()): |
71 reg.organisation = registration_form.data.get('organisation') |
83 reg.organisation = registration_form.data.get('organisation') |
72 reg.occupation = registration_form.data.get('occupation') |
84 reg.occupation = registration_form.data.get('occupation') |
73 reg.city = registration_form.data.get('city') |
85 reg.city = registration_form.data.get('city') |
74 reg.phone_num = registration_form.data.get('phone_num') |
86 reg.phone_num = registration_form.data.get('phone_num') |
75 reg.postcode = registration_form.data.get('postcode') |
87 reg.postcode = registration_form.data.get('postcode') |
83 reg.sprint = registration_form.data.get( |
95 reg.sprint = registration_form.data.get( |
84 'sprint') and True or False |
96 'sprint') and True or False |
85 reg.save() |
97 reg.save() |
86 |
98 |
87 wifi = wifi_form.save(reg.registrant, reg.scope) |
99 wifi = wifi_form.save(reg.registrant, reg.scope) |
|
100 acco = acco_form.save(reg.registrant, reg.scope) |
88 |
101 |
89 # Saved.. redirect |
102 # Saved.. redirect |
90 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
103 redirect_to = reverse('scipycon_account', kwargs={'scope': scope}) |
91 |
104 |
92 return set_message_cookie(redirect_to, |
105 return set_message_cookie(redirect_to, |
93 msg = u'Your changes have been saved.') |
106 msg = u'Your changes have been saved.') |
94 else: |
|
95 import logging |
|
96 logging.error(registration_form.data) |
|
97 raise "Bow Bow" |
|
98 else: |
107 else: |
99 registration_form = RegistrationEditForm(initial={ |
108 registration_form = RegistrationEditForm(initial={ |
100 'id' : id, |
109 'id' : id, |
101 'organisation' : reg.organisation, |
110 'organisation' : reg.organisation, |
102 'occupation' : reg.occupation, |
111 'occupation' : reg.occupation, |
112 wifi_form = WifiForm(initial={ |
121 wifi_form = WifiForm(initial={ |
113 'user': wifi.user, |
122 'user': wifi.user, |
114 'scope': wifi.scope, |
123 'scope': wifi.scope, |
115 'wifi': wifi.wifi |
124 'wifi': wifi.wifi |
116 }) |
125 }) |
|
126 acco_form = AccommodationForm(initial={ |
|
127 'user': acco.user, |
|
128 'scope': acco.scope, |
|
129 'sex': acco.sex, |
|
130 'accommodation_required': acco.accommodation_required, |
|
131 'accommodation_days': acco.accommodation_days, |
|
132 }) |
117 |
133 |
118 return render_to_response( |
134 return render_to_response( |
119 template_name, RequestContext(request, { |
135 template_name, RequestContext(request, { |
120 'params': {'scope': scope}, |
136 'params': {'scope': scope}, |
121 'registration': {'id': id}, |
137 'registration': {'id': id}, |
122 'registration_form': registration_form, |
138 'registration_form': registration_form, |
123 'wifi_form': wifi_form})) |
139 'wifi_form': wifi_form, |
|
140 'acco_form': acco_form})) |
124 |
141 |
125 def submit_registration(request, scope, |
142 def submit_registration(request, scope, |
126 template_name='registration/submit-registration.html'): |
143 template_name='registration/submit-registration.html'): |
127 """Allows user to edit registration |
144 """Allows user to edit registration |
128 """ |
145 """ |
155 |
172 |
156 if request.method == 'POST': |
173 if request.method == 'POST': |
157 registration_form = RegistrationSubmitForm(data=request.POST) |
174 registration_form = RegistrationSubmitForm(data=request.POST) |
158 registrant_form = RegistrantForm(data=request.POST) |
175 registrant_form = RegistrantForm(data=request.POST) |
159 wifi_form = WifiForm(data=request.POST) |
176 wifi_form = WifiForm(data=request.POST) |
|
177 acco_form = AccommodationForm(data=request.POST) |
160 |
178 |
161 if request.POST.get('action', None) == 'login': |
179 if request.POST.get('action', None) == 'login': |
162 login_form = AuthenticationForm(data=request.POST) |
180 login_form = AuthenticationForm(data=request.POST) |
163 if login_form.is_valid(): |
181 if login_form.is_valid(): |
164 |
182 |
189 newuser = user |
207 newuser = user |
190 |
208 |
191 else: |
209 else: |
192 newuser = user |
210 newuser = user |
193 |
211 |
194 if registration_form.is_valid() and newuser and wifi_form.is_valid(): |
212 if (registration_form.is_valid() and newuser and wifi_form.is_valid() |
|
213 and acco_form.is_valid()): |
195 allow_contact = registration_form.cleaned_data.get( |
214 allow_contact = registration_form.cleaned_data.get( |
196 'allow_contact') and True or False |
215 'allow_contact') and True or False |
197 conference = registration_form.cleaned_data.get( |
216 conference = registration_form.cleaned_data.get( |
198 'conference') and True or False |
217 'conference') and True or False |
199 tutorial = registration_form.cleaned_data.get('tutorial') and \ |
218 tutorial = registration_form.cleaned_data.get('tutorial') and \ |
224 slug = 'SCIPYIN2010%04d' % id |
243 slug = 'SCIPYIN2010%04d' % id |
225 reg.slug = slug |
244 reg.slug = slug |
226 reg.save() |
245 reg.save() |
227 |
246 |
228 wifi = wifi_form.save(registrant, scope_entity) |
247 wifi = wifi_form.save(registrant, scope_entity) |
229 |
248 acco = acco_form.save(registrant, scope_entity) |
230 # send_confirmation(registrant, scope_entity,password=passwd) |
249 send_confirmation(registrant, scope_entity, password=passwd) |
231 |
|
232 redirect_to = reverse('scipycon_registrations', |
250 redirect_to = reverse('scipycon_registrations', |
233 kwargs={'scope': scope}) |
251 kwargs={'scope': scope}) |
234 return set_message_cookie(redirect_to, |
252 return set_message_cookie(redirect_to, |
235 msg = u'Thank you, your registration has been submitted '\ |
253 msg = u'Thank you, your registration has been submitted '\ |
236 'and an email has been sent with payment details.') |
254 'and an email has been sent with payment details.') |
237 |
255 |
238 else: |
256 else: |
239 registration_form = RegistrationSubmitForm() |
257 registration_form = RegistrationSubmitForm() |
240 registrant_form = RegistrantForm() |
258 registrant_form = RegistrantForm() |
241 wifi_form = WifiForm() |
259 wifi_form = WifiForm() |
|
260 acco_form = AccommodationForm() |
242 |
261 |
243 login_form = AuthenticationForm() |
262 login_form = AuthenticationForm() |
244 |
263 |
245 |
264 |
246 return render_to_response(template_name, RequestContext(request, { |
265 return render_to_response(template_name, RequestContext(request, { |
247 'params': {'scope': scope}, |
266 'params': {'scope': scope}, |
248 'registration_form': registration_form, |
267 'registration_form': registration_form, |
249 'registrant_form' : registrant_form, |
268 'registrant_form' : registrant_form, |
250 'over_reg' : reg_count >= REG_TOTAL and True or False, |
269 'over_reg' : reg_count >= REG_TOTAL and True or False, |
|
270 'acco_form': acco_form, |
251 'wifi_form' : wifi_form, |
271 'wifi_form' : wifi_form, |
252 'message' : message, |
272 'message' : message, |
253 'login_form' : login_form |
273 'login_form' : login_form |
254 })) |
274 })) |
255 |
275 |