Skip to content

Commit

Permalink
Catch the error for when there is no poll to vote on #1
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamBrenner committed Dec 5, 2015
1 parent 99a8f15 commit aad7281
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions wagtailpolls/templatetags/wagtailpolls_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ def querystring(context, **kwargs):

@register.simple_tag(takes_context=True)
def vote(context, poll):
if poll is None:
return reverse('wagtailpolls_vote', kwargs={'poll_pk': None})
return reverse('wagtailpolls_vote', kwargs={'poll_pk': poll.pk})
11 changes: 9 additions & 2 deletions wagtailpolls/views/vote.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib.auth.decorators import permission_required
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, JsonResponse
from ..models import Poll, Vote
from django.shortcuts import get_object_or_404

from ..forms import VoteForm
from ..models import Poll, Vote


def vote_data(poll):
Expand All @@ -22,6 +23,12 @@ def vote_data(poll):

@permission_required('wagtailadmin.access_admin')
def vote(request, poll_pk):
try:
int(poll_pk)

except ValueError:
return HttpResponse("<h1>Oops, there is no poll to vote on!</h1>", status=500)

poll = get_object_or_404(Poll, pk=poll_pk)

form = VoteForm(data=request.POST, poll=poll, request=request)
Expand Down

0 comments on commit aad7281

Please sign in to comment.