|
1 import csv |
1 import datetime |
2 import datetime |
2 import time |
3 import time |
3 |
4 |
4 from django.contrib.auth import authenticate |
5 from django.contrib.auth import authenticate |
5 from django.contrib.auth import login |
6 from django.contrib.auth import login |
6 from django.contrib.auth.decorators import login_required |
7 from django.contrib.auth.decorators import login_required |
7 from django.contrib.auth.forms import AuthenticationForm |
8 from django.contrib.auth.forms import AuthenticationForm |
8 from django.contrib.auth.models import User |
9 from django.contrib.auth.models import User |
9 from django.core.exceptions import ObjectDoesNotExist |
10 from django.core.exceptions import ObjectDoesNotExist |
10 from django.core.urlresolvers import reverse |
11 from django.core.urlresolvers import reverse |
|
12 from django.http import HttpResponse |
|
13 from django.http import HttpResponseRedirect |
11 from django.shortcuts import render_to_response |
14 from django.shortcuts import render_to_response |
12 from django.template import loader |
15 from django.template import loader |
13 from django.template import RequestContext |
16 from django.template import RequestContext |
14 |
17 |
15 from project.scipycon.base.models import Event |
18 from project.scipycon.base.models import Event |
314 redirect_to = reverse('scipycon_login', kwargs={'scope': scope}) |
317 redirect_to = reverse('scipycon_login', kwargs={'scope': scope}) |
315 return set_message_cookie( |
318 return set_message_cookie( |
316 redirect_to, msg = u'You must be a staff on this website to ' |
319 redirect_to, msg = u'You must be a staff on this website to ' |
317 'access this page.') |
320 'access this page.') |
318 |
321 |
319 q = Registration.objects.all() |
322 reg_q = Registration.objects.all() |
320 conf_num = q.filter(conference=True).count() |
323 conf_num = reg_q.filter(conference=True).count() |
321 tut_num = q.filter(tutorial=True).count() |
324 tut_num = reg_q.filter(tutorial=True).count() |
322 sprint_num = q.filter(sprint=True).count() |
325 sprint_num = reg_q.filter(sprint=True).count() |
|
326 |
|
327 acco_q = Accommodation.objects.all() |
|
328 acco_days = [] |
|
329 acco_days.append(acco_q.filter(accommodation_on_1st=True).count()) |
|
330 acco_days.append(acco_q.filter(accommodation_on_2nd=True).count()) |
|
331 acco_days.append(acco_q.filter(accommodation_on_3rd=True).count()) |
|
332 acco_days.append(acco_q.filter(accommodation_on_4th=True).count()) |
|
333 acco_days.append(acco_q.filter(accommodation_on_5th=True).count()) |
|
334 acco_days.append(acco_q.filter(accommodation_on_6th=True).count()) |
323 |
335 |
324 return render_to_response(template_name, RequestContext(request, |
336 return render_to_response(template_name, RequestContext(request, |
325 {'params': {'scope': scope}, |
337 {'params': {'scope': scope}, |
326 'conf_num': conf_num, |
338 'conf_num': conf_num, |
327 'tut_num': tut_num, |
339 'tut_num': tut_num, |
328 'sprint_num': sprint_num, |
340 'sprint_num': sprint_num, |
|
341 'acco_days': acco_days, |
329 })) |
342 })) |
|
343 |
|
344 @login_required |
|
345 def regstats_download(request, scope): |
|
346 """Sends a downloadable PDF for registration statistics |
|
347 """ |
|
348 |
|
349 if not request.user.is_staff: |
|
350 redirect_to = reverse('scipycon_login') |
|
351 return HttpResponseRedirect(redirect_to) |
|
352 |
|
353 filename = 'regstats%s.csv' % datetime.datetime.strftime( |
|
354 datetime.datetime.now(), '%Y%m%d%H%M%S') |
|
355 |
|
356 response = HttpResponse(mimetype='text/csv') |
|
357 response['Content-Disposition'] = 'attachment; filename=%s' % ( |
|
358 filename) |
|
359 |
|
360 output = csv.writer(response) |
|
361 |
|
362 output.writerow(['Name', 'City' |
|
363 'Registration Fees Paid', |
|
364 'Attending Conference', |
|
365 'Attending Tutorial', |
|
366 'Attending Sprint', |
|
367 'Laptop Identification Number', |
|
368 'Accommodation Fees Paid', |
|
369 'Accommodation on 12th night', |
|
370 'Accommodation on 13th night', |
|
371 'Accommodation on 14th night', |
|
372 'Accommodation on 15th night', |
|
373 'Accommodation on 16th night', |
|
374 'Accommodation on 17th night']) |
|
375 |
|
376 regs = Registration.objects.all() |
|
377 for reg in regs: |
|
378 row = [] |
|
379 row.append(reg.registrant.get_full_name()) |
|
380 row.append(reg.city) |
|
381 row.append('Yes' if reg.registrant.payment_set.get().confirmed |
|
382 else 'No') |
|
383 row.append('Yes' if reg.conference else 'No') |
|
384 row.append('Yes' if reg.tutorial else 'No') |
|
385 row.append('Yes' if reg.sprint else 'No') |
|
386 row.append(reg.registrant.wifi_set.get().registration_id) |
|
387 row.append('Yes' if reg.registrant.payment_set.get().acco_confirmed |
|
388 else 'No') |
|
389 acco, created = reg.registrant.accommodation_set.get_or_create() |
|
390 row.append('Yes' if acco.accommodation_on_1st else 'No') |
|
391 row.append('Yes' if acco.accommodation_on_2nd else 'No') |
|
392 row.append('Yes' if acco.accommodation_on_3rd else 'No') |
|
393 row.append('Yes' if acco.accommodation_on_4th else 'No') |
|
394 row.append('Yes' if acco.accommodation_on_5th else 'No') |
|
395 row.append('Yes' if acco.accommodation_on_6th else 'No') |
|
396 output.writerow(row) |
|
397 |
|
398 #output.writerow() |
|
399 return response |
330 |
400 |
331 |
401 |
332 @login_required |
402 @login_required |
333 def manage_payments(request, scope, |
403 def manage_payments(request, scope, |
334 template_name='registration/manage_payments.html'): |
404 template_name='registration/manage_payments.html'): |