summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--polls/views.py7
-rw-r--r--static/styles.css4
-rw-r--r--templates/createOrEdit.html3
-rw-r--r--templates/main.html1
4 files changed, 13 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 = []
diff --git a/static/styles.css b/static/styles.css
index 7728000..2b88e3c 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -72,6 +72,10 @@ margin:5px;
overflow:auto;
}
+.error{
+color:red;
+}
+
table.poll{
text-align:center;
}
diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html
index abc949e..cee7616 100644
--- a/templates/createOrEdit.html
+++ b/templates/createOrEdit.html
@@ -1,6 +1,9 @@
{% extends "base.html" %}
{% block content %}
+ {% if not new and not choices %}
+ <p class='error'>As long as no option was added to the poll, it will not be made available.</p>
+ {% endif %}
<h2>{% if new %}New{% else %}Edit{% endif %} poll</h2>
{% if error %}<p class='error'>{{ error }}</p>{% endif %}
<form action="{{admin_url}}" method="post">
diff --git a/templates/main.html b/templates/main.html
index b51e7fe..34f6609 100644
--- a/templates/main.html
+++ b/templates/main.html
@@ -1,6 +1,7 @@
{% extends "base.html" %}
{% block content %}
+{% if error %}<p class='error'>{{error}}</p>{%endif%}
<h2><a href='edit/0'>Create a poll</a></h2>
<p>Create a new sondage for take a decision, find a date for a meeting, etc.</p>