diff options
author | Madhusudan.C.S | 2010-11-02 22:13:12 +0530 |
---|---|---|
committer | Madhusudan.C.S | 2010-11-02 22:13:12 +0530 |
commit | 2f5eb55007dd5dae1c37fa82fa91aa91089c8311 (patch) | |
tree | c243d589acc78940b23f2b3c5820f56e21756854 /project | |
parent | e4b61f9d89534ca8829f2a22e5c7ee53b75f4805 (diff) | |
download | scipycon-2f5eb55007dd5dae1c37fa82fa91aa91089c8311.tar.gz scipycon-2f5eb55007dd5dae1c37fa82fa91aa91089c8311.tar.bz2 scipycon-2f5eb55007dd5dae1c37fa82fa91aa91089c8311.zip |
Copy the download csv code that was earlier written but scraped.
Diffstat (limited to 'project')
-rw-r--r-- | project/scipycon/registration/views.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/project/scipycon/registration/views.py b/project/scipycon/registration/views.py index ef5f9ee..6dea7e3 100644 --- a/project/scipycon/registration/views.py +++ b/project/scipycon/registration/views.py @@ -252,3 +252,67 @@ def submit_registration(request, scope, 'message' : message, 'login_form' : login_form })) + + +@login_required +def regstats(request, scope, + template_name='registration/regstats.html'): + """View that gives the statistics of registrants. + """ + from project.scipycon.registration.forms import RegistrationAdminSelectForm + if not request.user.is_staff: + redirect_to = reverse('scipycon_login', kwargs={'scope': scope}) + + if request.method == "POST": + form = RegistrationAdminSelectForm(request.POST) + if form.is_valid(): + conference = form.cleaned_data['by_conference'] + tutorial = form.cleaned_data['by_tutorial'] + sprint = form.cleaned_data['by_sprint'] + include = form.cleaned_data['include'] + + q = Registration.objects.all() + q = q.filter(conference=conference) + q = q.filter(tutorial=tutorial) + q = q.filter(sprint=sprint) + + q = q.order_by('registrant__email') + + query = q.query + results = list(q) + + if include == []: + # default to include all fields + include = [i[0] for i in IC] + if results: + response = HttpResponse(mimetype='text/csv') + response['Content-Disposition'] = 'attachment; filename=registrations.csv' + output = csv.writer(response) + output.writerow([h for h in include]) + for row in results: + conference = row.conference == True and 'yes' or 'no' + tutorial = row.tutorial == True and 'yes' or 'no' + sprint = row.sprint == True and 'yes' or 'no' + wrow = [] + if 'Name' in include: + wrow.append( + row.registrant.get_full_name().encode('utf-8')) + if 'Email' in include: + wrow.append(row.registrant.email.encode('utf-8')) + if 'Organisation' in include: + wrow.append(row.organisation.encode('utf-8')) + if 'Conference' in include: + wrow.append(conference) + if 'Tutorial' in include: + wrow.append(tutorial) + if 'Sprint' in include: + wrow.append(sprint) + output.writerow(wrow) + return response + else: + no_results = u'No results found for the query' + + else: + form = RegistrationAdminSelectForm() + return render_to_response(template_name, RequestContext(request, + locals())) |