Skip to content

Commit

Permalink
Support next parameter on vote
Browse files Browse the repository at this point in the history
  • Loading branch information
EnTeQuAk committed Sep 29, 2013
1 parent f2a9817 commit e0c9a0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions bakery/socialize/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
@login_required
@require_POST
def vote(request, unvote=False):
next = request.GET.get('next', '')
cookie_id = int(request.POST.get('c'))
try:
cookie = Cookie.objects.get(pk=cookie_id)
if unvote:
do_unvote(request.user, cookie)
else:
do_vote(request.user, cookie)
redirect = reverse('cookies:detail', kwargs={
'owner_name': cookie.owner_name,
'name': cookie.name,
})
return HttpResponseRedirect(redirect)
if not next:
next = reverse('cookies:detail', kwargs={
'owner_name': cookie.owner_name,
'name': cookie.name,
})
return HttpResponseRedirect(next)
except Cookie.DoesNotExist:
raise Http404('Cookie does not exist')

Expand Down
4 changes: 2 additions & 2 deletions bakery/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ <h2>Cookies</h2>
<div class="hidden-xs hidden-sm actions">
{% if request.user.is_authenticated %}
{% if cookie.pk in voted_cookie_ids %}
<form action="{% url 'socialize:unvote' %}" method="POST">
<form action="{% url 'socialize:unvote' %}?next={{ request.get_full_path }}" method="POST">
{% csrf_token %}
<input type="hidden" name="c" value="{{ cookie.id }}">
<input type="submit" value="Vote" title="Unvote" class="btn btn-xs btn-primary btn-cookie">
</form>
{% else %}
<form action="{% url 'socialize:vote' %}" method="POST">
<form action="{% url 'socialize:vote' %}?next={{ request.get_full_path }}" method="POST">
{% csrf_token %}
<input type="hidden" name="c" value="{{ cookie.id }}">
<input type="submit" value="" title="Vote" class="btn btn-xs btn-default btn-cookie">
Expand Down
4 changes: 2 additions & 2 deletions bakery/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ <h3>{% trans "Cookies" %}</h3>
<div class="hidden-xs hidden-sm actions">
{% if request.user.is_authenticated %}
{% if cookie.pk in voted_cookie_ids %}
<form action="{% url 'socialize:unvote' %}" method="POST">
<form action="{% url 'socialize:unvote' %}?next={{ request.get_full_path }}" method="POST">
{% csrf_token %}
<input type="hidden" name="c" value="{{ cookie.id }}">
<input type="submit" value="" title="Vote" class="btn btn-xs btn-primary btn-cookie">
</form>
{% else %}
<form action="{% url 'socialize:vote' %}" method="POST">
<form action="{% url 'socialize:vote' %}?next={{ request.get_full_path }}" method="POST">
{% csrf_token %}
<input type="hidden" name="c" value="{{ cookie.id }}">
<input type="submit" value="" title="Vote" class="btn btn-xs btn-default btn-cookie">
Expand Down

0 comments on commit e0c9a0f

Please sign in to comment.