# HG changeset patch # User Madhusudan.C.S # Date 1291901892 -19800 # Node ID 21dc37050a3793a78d16e0ad1a05c8a2ddb8470b # Parent bc29a1bb4010fbe4be827c0a8d13332d1a9a423a Make downloadable CSV for stats page. diff -r bc29a1bb4010 -r 21dc37050a37 development.cfg --- a/development.cfg Wed Dec 08 23:18:35 2010 +0530 +++ b/development.cfg Thu Dec 09 19:08:12 2010 +0530 @@ -5,4 +5,6 @@ [django] settings = development -eggs = ${buildout:eggs} +eggs = + ${buildout:eggs} + ${reportlab:eggs} diff -r bc29a1bb4010 -r 21dc37050a37 project/scipycon/registration/views.py --- a/project/scipycon/registration/views.py Wed Dec 08 23:18:35 2010 +0530 +++ b/project/scipycon/registration/views.py Thu Dec 09 19:08:12 2010 +0530 @@ -1,3 +1,4 @@ +import csv import datetime import time @@ -8,6 +9,8 @@ from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse +from django.http import HttpResponse +from django.http import HttpResponseRedirect from django.shortcuts import render_to_response from django.template import loader from django.template import RequestContext @@ -316,18 +319,85 @@ redirect_to, msg = u'You must be a staff on this website to ' 'access this page.') - q = Registration.objects.all() - conf_num = q.filter(conference=True).count() - tut_num = q.filter(tutorial=True).count() - sprint_num = q.filter(sprint=True).count() + reg_q = Registration.objects.all() + conf_num = reg_q.filter(conference=True).count() + tut_num = reg_q.filter(tutorial=True).count() + sprint_num = reg_q.filter(sprint=True).count() + + acco_q = Accommodation.objects.all() + acco_days = [] + acco_days.append(acco_q.filter(accommodation_on_1st=True).count()) + acco_days.append(acco_q.filter(accommodation_on_2nd=True).count()) + acco_days.append(acco_q.filter(accommodation_on_3rd=True).count()) + acco_days.append(acco_q.filter(accommodation_on_4th=True).count()) + acco_days.append(acco_q.filter(accommodation_on_5th=True).count()) + acco_days.append(acco_q.filter(accommodation_on_6th=True).count()) return render_to_response(template_name, RequestContext(request, {'params': {'scope': scope}, 'conf_num': conf_num, 'tut_num': tut_num, 'sprint_num': sprint_num, + 'acco_days': acco_days, })) +@login_required +def regstats_download(request, scope): + """Sends a downloadable PDF for registration statistics + """ + + if not request.user.is_staff: + redirect_to = reverse('scipycon_login') + return HttpResponseRedirect(redirect_to) + + filename = 'regstats%s.csv' % datetime.datetime.strftime( + datetime.datetime.now(), '%Y%m%d%H%M%S') + + response = HttpResponse(mimetype='text/csv') + response['Content-Disposition'] = 'attachment; filename=%s' % ( + filename) + + output = csv.writer(response) + + output.writerow(['Name', 'City' + 'Registration Fees Paid', + 'Attending Conference', + 'Attending Tutorial', + 'Attending Sprint', + 'Laptop Identification Number', + 'Accommodation Fees Paid', + 'Accommodation on 12th night', + 'Accommodation on 13th night', + 'Accommodation on 14th night', + 'Accommodation on 15th night', + 'Accommodation on 16th night', + 'Accommodation on 17th night']) + + regs = Registration.objects.all() + for reg in regs: + row = [] + row.append(reg.registrant.get_full_name()) + row.append(reg.city) + row.append('Yes' if reg.registrant.payment_set.get().confirmed + else 'No') + row.append('Yes' if reg.conference else 'No') + row.append('Yes' if reg.tutorial else 'No') + row.append('Yes' if reg.sprint else 'No') + row.append(reg.registrant.wifi_set.get().registration_id) + row.append('Yes' if reg.registrant.payment_set.get().acco_confirmed + else 'No') + acco, created = reg.registrant.accommodation_set.get_or_create() + row.append('Yes' if acco.accommodation_on_1st else 'No') + row.append('Yes' if acco.accommodation_on_2nd else 'No') + row.append('Yes' if acco.accommodation_on_3rd else 'No') + row.append('Yes' if acco.accommodation_on_4th else 'No') + row.append('Yes' if acco.accommodation_on_5th else 'No') + row.append('Yes' if acco.accommodation_on_6th else 'No') + output.writerow(row) + + #output.writerow() + return response + @login_required def manage_payments(request, scope, diff -r bc29a1bb4010 -r 21dc37050a37 project/templates/registration/regstats.html --- a/project/templates/registration/regstats.html Wed Dec 08 23:18:35 2010 +0530 +++ b/project/templates/registration/regstats.html Thu Dec 09 19:08:12 2010 +0530 @@ -22,5 +22,16 @@ Sprint {{ sprint_num }} +{% for acco in acco_days %} + + Accommodation on {{ forloop.counter|add:"11" }} + {{ acco }} + + {% endfor %} + + +To download PDF +here + {% endblock content %} diff -r bc29a1bb4010 -r 21dc37050a37 project/urls.py --- a/project/urls.py Wed Dec 08 23:18:35 2010 +0530 +++ b/project/urls.py Thu Dec 09 19:08:12 2010 +0530 @@ -53,6 +53,8 @@ 'edit_registration', name='scipycon_edit_registration'), url(r'^%s/regstats/$'% (SCOPE_ARG_PATTERN), 'regstats', name="scipycon_regstats"), + url(r'^%s/regstats/download$'% (SCOPE_ARG_PATTERN), + 'regstats_download', name="scipycon_regstats_download"), url(r'^%s/manage_payments/$'% (SCOPE_ARG_PATTERN), 'manage_payments', name="scipycon_manage_payments"), )