Commit 3a062210 authored by chris's avatar chris

"Forget me": added clear_cookie link for anonymous users

parent 32bb2df3
......@@ -3,6 +3,7 @@ from django.contrib.auth.forms import UserCreationForm
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse
def register(request):
if request.method == 'POST':
......@@ -16,3 +17,8 @@ def register(request):
'form': form,
}, context_instance=RequestContext(request))
def clear_cookie(request, poll_id):
request.session.clear()
return HttpResponseRedirect(reverse('nuages.sondage.views.vote', args=(poll_id,)))
# Here are the views for nuage.sondage
# Here are the views for nuages.sondage
import datetime
from django.http import HttpResponse, HttpResponseRedirect
......@@ -121,8 +121,6 @@ def editchoices(request, poll_id):
vforms = OrderedItemFormset(instance=poll)
return render_to_response('sondage/choice_form.html', {'object': poll, 'vforms': vforms, 'language_code': language_code,}, context_instance=RequestContext(request))
def make_buletin_form(poll, **kwargs):
return [ [VoteForm(prefix=choice) ] for choice in Choice.objects.filter(poll=poll.id) ]
......@@ -131,6 +129,7 @@ def vote(request, poll_id):
error_message = None
poll = get_object_or_404(Poll.objects.all(),id=poll_id)
has_voted = False
if request.method == 'POST':
......@@ -183,6 +182,7 @@ def vote(request, poll_id):
key = 'has_voted-' + poll.id
request.session[key] = True # This writes cookie
request.session['name'] = voter # This writes cookie
has_voted = True # Used to show "Forget me"
else:
old = Vote.objects.get(choice=choice,bulletin=bulletin)
......@@ -220,7 +220,7 @@ def vote(request, poll_id):
voter = str(request.user)
try:
bulletin = Bulletin.objects.get(poll=poll,voter=voter)
error_message = " you have voted."
error_message = " You have voted."
diff = len(vforms) - len(Vote.objects.filter(bulletin=bulletin))
if diff == 0:
"""
......@@ -237,11 +237,12 @@ def vote(request, poll_id):
error_message = "Login let you modify your vote anytime."
key = 'has_voted-' + poll.id
if request.session.get(key, False):
has_voted = True # Used to show "Forget me"
voter = request.session.get('name')
#error_message = 'Modify your vote? (clear cookie if you are not ' + voter + ')'
try:
bulletin = Bulletin.objects.get(poll=poll,voter=voter)
error_message = ' you have voted, clear cookie if you are not ' + voter
error_message = voter + ' has voted'
diff = len(vforms) - len(Vote.objects.filter(bulletin=bulletin))
if diff == 0:
"""
......@@ -257,6 +258,6 @@ def vote(request, poll_id):
form = BulletinForm(instance=poll,initial={'voter': voter})
#form = BulletinForm(instance=poll)
current_site = settings.SITE + poll.id
return render_to_response('sondage/poll_detail.html', {'object': poll, 'form': form, 'vforms':vforms, 'error_message':error_message, 'current_site': current_site}, context_instance=RequestContext(request))
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))
......@@ -27,7 +27,7 @@
<a href="/user/logout/">Logout</a>
{% else %}
<a href="/user/login/">Login</a>
{% endif %}&nbsp;
{% endif %}
{% block menu %}{% endblock %}
<span class="notify">
......
{% extends "base.html" %}
{% load i18n %}
{% block menu %}
{% if has_voted %}
<a title="Clear cookie, only {{object.author}} will be able to change your vote" href="/{{object.id}}/clear/">Forget me</a>
{% endif %}
{% endblock %}
{% block title %}nuages - {{object}}{% endblock %}
{% block chapeau %}
......
......@@ -44,7 +44,7 @@ urlpatterns = patterns('',
(r'^user/success$', 'django.views.generic.simple.direct_to_template', {'template': 'registration/success.html'}),
(r'^i18n/', include('django.conf.urls.i18n')),
(r'^(?P<poll_id>\w{4})/clear/', 'nuages.sondage.userviews.clear_cookie'),
)
......
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