diff options
| author | etienne <etienne@07715635-78ed-41b0-aaf1-0afda6c37f35> | 2008-08-06 18:40:47 +0000 |
|---|---|---|
| committer | etienne <etienne@07715635-78ed-41b0-aaf1-0afda6c37f35> | 2008-08-06 18:40:47 +0000 |
| commit | 25cb65439859e7fd3e9b28815d3d620affc145ec (patch) | |
| tree | 000156332ff7023c87bc22ccad6823f7ebdbfc49 /polls/views.py | |
| parent | c0f702909fe00fde38500ba3d6981137c3d64d7a (diff) | |
| download | Papillon-25cb65439859e7fd3e9b28815d3d620affc145ec.tar.bz2 Papillon-25cb65439859e7fd3e9b28815d3d620affc145ec.zip | |
Poll with no choices are no longer available
Diffstat (limited to 'polls/views.py')
| -rw-r--r-- | polls/views.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/polls/views.py b/polls/views.py index deee26c..040a9b9 100644 --- a/polls/views.py +++ b/polls/views.py @@ -118,19 +118,21 @@ def poll(request, poll_url): try: poll = Poll.objects.filter(base_url=poll_url)[0] except IndexError: + poll = None + choices = Choice.objects.filter(poll=poll).order_by('order') + if not choices or not poll: url = "/".join(request.path.split('/')[:-3]) url += "?bad_poll=1" return HttpResponseRedirect(url) response_dct['base_url'] = \ "/".join(request.path.split('/')[:-2]) + '/%s/' % poll.base_url - choices = Choice.objects.filter(poll=poll).order_by('order') response_dct['choices'] = choices if 'author_name' in request.POST: if 'voter' in request.POST: try: author = PollUser.objects.filter(id=int(request.POST['voter']))[0] - except ValueError, IndexError: + except (ValueError, IndexError): author = None if author: author.name = request.POST['author_name'] @@ -181,6 +183,7 @@ def poll(request, poll_url): if choice not in selected_choices: v = Vote(voter=author, choice=choice, vote=0) v.save() + votes = [] votes = Vote.objects.extra(where=['choice_id IN (%s)' \ % ",".join([str(choice.id) for choice in choices])]) voters = [] |
