Commit 90aef5c5 authored by chris's avatar chris

Activate csv export.

parent 5fde5fae
# Here are the views for sondage
import datetime
import csv
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response
from django.core.urlresolvers import reverse
......@@ -280,10 +279,23 @@ def vote(request, poll_id):
return render_to_response('sondage/poll_detail.html', {'object': poll, 'form': form, 'vforms':vforms, 'error_message':error_message, 'has_voted': has_voted, 'current_site': current_site}, context_instance=RequestContext(request))
def exp_csv(request, poll_id):
import csv
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=nuages.csv'
poll = get_object_or_404(Poll.objects.all(),id=poll_id)
choices = Choice.objects.filter(poll=poll)
bulletins = Bulletin.objects.filter(poll=poll)
#writer = csv.writer(csv_file, quotechar='"', quoting=csv.QUOTE_ALL)
#for c in choices:
#writer.writerow(choices)
return HttpResponse(bulletins)
writer = csv.writer(response, quotechar='"', quoting=csv.QUOTE_ALL)
fr = ["",]
for c in choices:
fr.append(c)
writer.writerow(fr)
for b in bulletins:
r = [b.voter.encode("utf-8"),]
for v in Vote.objects.filter(bulletin=b):
r.append(v)
writer.writerow(r)
return response
......@@ -20,13 +20,13 @@
<div class="menu">
<a href="/">Nuages</a>&nbsp;
<a href="/" title="Homepage">Nuages</a>&nbsp;
{% block menu %}{% endblock %}
{% if user.is_authenticated %}
<a href="/user/logout/">Logout</a>
{% else %}
<a href="/user/login/">Login</a>
{% endif %}
{% block menu %}{% endblock %}
<span class="notify">
{% if error_message %}
......
......@@ -5,6 +5,7 @@
{% if has_voted %}
<a title=" {% trans 'Clear cookie, you will not be able to change your vote.' %} " href="/{{object.id}}/clear/">{% trans "Forget me" %}</a>
{% endif %}
<a title=" {% trans 'Export as csv spreadsheet' %} " href="/{{object.id}}/csv/">csv</a>
{% endblock %}
{% block title %}nuages - {{object}}{% endblock %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment