Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
etch
nuages
Commits
90aef5c5
Commit
90aef5c5
authored
May 30, 2011
by
Christophe Siraut
Browse files
Activate csv export.
parent
5fde5fae
Changes
3
Show whitespace changes
Inline
Side-by-side
sondage/views.py
View file @
90aef5c5
# 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
templates/base.html
View file @
90aef5c5
...
...
@@ -20,13 +20,13 @@
<div
class=
"menu"
>
<a
href=
"/"
>
Nuages
</a>
<a
href=
"/"
title=
"Homepage"
>
Nuages
</a>
{% 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 %}
...
...
templates/sondage/poll_detail.html
View file @
90aef5c5
...
...
@@ -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 %}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment