diff options
author | Madhusudan.C.S | 2010-12-09 19:08:12 +0530 |
---|---|---|
committer | Madhusudan.C.S | 2010-12-09 19:08:12 +0530 |
commit | 4116f4fbd97f29da90482f2a008fad227bbdb6e8 (patch) | |
tree | 4970125262ed0037b8b3a752d5a76fa0ead4a40c /project | |
parent | f2fb89848d262ceec98ef2fa9b66ff06c4848d28 (diff) | |
download | scipycon-4116f4fbd97f29da90482f2a008fad227bbdb6e8.tar.gz scipycon-4116f4fbd97f29da90482f2a008fad227bbdb6e8.tar.bz2 scipycon-4116f4fbd97f29da90482f2a008fad227bbdb6e8.zip |
Make downloadable CSV for stats page.
--HG--
extra : rebase_source : 8f9d21245ede2f73a693ba91bc72b5f698927b07
Diffstat (limited to 'project')
-rw-r--r-- | project/scipycon/registration/views.py | 78 | ||||
-rw-r--r-- | project/templates/registration/regstats.html | 11 | ||||
-rw-r--r-- | project/urls.py | 2 |
3 files changed, 87 insertions, 4 deletions
diff --git a/project/scipycon/registration/views.py b/project/scipycon/registration/views.py index 93a6233..75925d9 100644 --- a/project/scipycon/registration/views.py +++ b/project/scipycon/registration/views.py @@ -1,3 +1,4 @@ +import csv import datetime import time @@ -8,6 +9,8 @@ from django.contrib.auth.forms import AuthenticationForm 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 @@ def regstats(request, scope, 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 --git a/project/templates/registration/regstats.html b/project/templates/registration/regstats.html index f73a36f..2b9ea95 100644 --- a/project/templates/registration/regstats.html +++ b/project/templates/registration/regstats.html @@ -22,5 +22,16 @@ <td>Sprint</td> <td>{{ sprint_num }}</td> </tr> +{% for acco in acco_days %} + <tr> + <td>Accommodation on {{ forloop.counter|add:"11" }}</td> + <td>{{ acco }}</td> + </tr> + {% endfor %} </table> + + +To download PDF +<a href="{% url scipycon_regstats_download params.scope %}">here</a> + {% endblock content %} diff --git a/project/urls.py b/project/urls.py index 31fafbc..4559856 100644 --- a/project/urls.py +++ b/project/urls.py @@ -53,6 +53,8 @@ urlpatterns += patterns('project.scipycon.registration.views', '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"), ) |