315 {'params': {'scope': scope}, |
315 {'params': {'scope': scope}, |
316 'conf_num': conf_num, |
316 'conf_num': conf_num, |
317 'tut_num': tut_num, |
317 'tut_num': tut_num, |
318 'sprint_num': sprint_num, |
318 'sprint_num': sprint_num, |
319 })) |
319 })) |
|
320 |
|
321 |
|
322 @login_required |
|
323 def manage_payments(request, scope, |
|
324 template_name='registration/manage_payments.html'): |
|
325 """View that gives a form to manage payments. |
|
326 """ |
|
327 |
|
328 if not request.user.is_superuser: |
|
329 redirect_to = reverse('scipycon_login', kwargs={'scope': scope}) |
|
330 return set_message_cookie( |
|
331 redirect_to, msg = u'You must be an admin on this website to ' |
|
332 'access this page.') |
|
333 |
|
334 message = None |
|
335 |
|
336 scope_entity = Event.objects.get(scope=scope) |
|
337 |
|
338 if request.method == 'POST': |
|
339 post_data = request.POST |
|
340 list_user_ids = [] |
|
341 for user_id_string in post_data: |
|
342 id_str_list = user_id_string.split('_') |
|
343 if (len(id_str_list) == 3 and id_str_list[0] == 'registrant' and |
|
344 id_str_list[1] == 'id'): |
|
345 id = int(id_str_list[2]) |
|
346 reg_user = User.objects.get(pk=id) |
|
347 |
|
348 payment, created = reg_user.payment_set.get_or_create( |
|
349 user=reg_user, scope=scope_entity) |
|
350 |
|
351 payment.paid = True |
|
352 payment.save() |
|
353 |
|
354 list_user_ids.append(id) |
|
355 |
|
356 # This is done to unset for the confirmation for users for whom |
|
357 # mistakenly confirmation was set. |
|
358 # (TODO) This is a very expensive operation, any better solution |
|
359 # will be appreciated. |
|
360 unpaid_users = User.objects.exclude(pk__in=list_user_ids) |
|
361 for user in unpaid_users: |
|
362 payment, created = user.payment_set.get_or_create( |
|
363 user=user, scope=scope_entity) |
|
364 payment.paid = False |
|
365 payment.save() |
|
366 |
|
367 registrants = Registration.objects.all() |
|
368 |
|
369 return render_to_response(template_name, RequestContext(request, |
|
370 {'params': {'scope': scope}, |
|
371 'registrants': registrants, |
|
372 })) |