Make downloadable CSV for stats page.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Thu, 09 Dec 2010 19:08:12 +0530
changeset 342 21dc37050a37
parent 341 bc29a1bb4010
child 343 debfd9506f40
Make downloadable CSV for stats page.
development.cfg
project/scipycon/registration/views.py
project/templates/registration/regstats.html
project/urls.py
--- 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}
--- 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,
--- 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 @@
  <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 %}
--- 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"),
     )