summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--locale/fr/LC_MESSAGES/django.po64
-rw-r--r--polls/models.py34
-rw-r--r--polls/views.py178
-rw-r--r--static/styles.css8
-rw-r--r--templates/createOrEdit.html57
-rw-r--r--templates/vote.html34
6 files changed, 233 insertions, 142 deletions
diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po
index b8bf7b5..20ba57e 100644
--- a/locale/fr/LC_MESSAGES/django.po
+++ b/locale/fr/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-08-20 00:40+0200\n"
+"POT-Creation-Date: 2008-08-21 02:45+0200\n"
"PO-Revision-Date: 2008-08-20 00:22+0200\n"
"Last-Translator: Étienne Loks <etienne.loks@peacefrogs.net>,\n"
"Language-Team: fr\n"
@@ -24,16 +24,24 @@ msgstr "Français"
msgid "English"
msgstr "Anglais"
-#: templates/vote.html:21 templates/vote.html.py:41
-#: templates/createOrEdit.html:63
+#: templates/vote.html:32 templates/vote.html.py:67
+#: templates/createOrEdit.html:62
msgid "Edit"
msgstr "Modifier"
-#: templates/vote.html:35
+#: templates/vote.html:36 polls/models.py:68
+msgid "No"
+msgstr "Non"
+
+#: templates/vote.html:36 polls/models.py:66
+msgid "Yes"
+msgstr "Oui"
+
+#: templates/vote.html:61
msgid "Sum"
msgstr "Somme"
-#: templates/vote.html:41
+#: templates/vote.html:67
msgid "Participate"
msgstr "Participer"
@@ -68,7 +76,7 @@ msgstr "Adresse d'administration"
msgid "Address to modify the current poll"
msgstr "Adresse de modification de ce sondage"
-#: templates/createOrEdit.html:23 polls/views.py:56
+#: templates/createOrEdit.html:23 polls/views.py:83
msgid "Author name"
msgstr "Nom de l'auteur"
@@ -76,7 +84,7 @@ msgstr "Nom de l'auteur"
msgid "Name, firstname or nickname of the author"
msgstr "Nom, prénom ou surnom de l'auteur"
-#: templates/createOrEdit.html:28 polls/views.py:57
+#: templates/createOrEdit.html:28 polls/views.py:84
msgid "Poll name"
msgstr "Nom du sondage"
@@ -84,7 +92,7 @@ msgstr "Nom du sondage"
msgid "Global name to present the poll"
msgstr "Nom général pour présenter le sondage"
-#: templates/createOrEdit.html:33 polls/views.py:58
+#: templates/createOrEdit.html:33 polls/views.py:85
msgid "Poll description"
msgstr "Description du sondage"
@@ -92,7 +100,7 @@ msgstr "Description du sondage"
msgid "Precise description of the poll"
msgstr "Description précise du sondage"
-#: templates/createOrEdit.html:38 polls/views.py:59
+#: templates/createOrEdit.html:38 polls/views.py:86
msgid "Poll type"
msgstr "Type du sondage"
@@ -114,23 +122,23 @@ msgstr ""
"Sondage pondéré permet aux participants de mettre des votes négatifs pour "
"certains choix"
-#: templates/createOrEdit.html:47 polls/models.py:27
+#: templates/createOrEdit.html:47
msgid "One choice poll"
msgstr "Sondage à choix unique"
-#: templates/createOrEdit.html:53
+#: templates/createOrEdit.html:52
msgid "Choices"
msgstr "Choix"
-#: templates/createOrEdit.html:53
+#: templates/createOrEdit.html:52
msgid "Delete?"
msgstr "Supprimer ?"
-#: templates/createOrEdit.html:58
+#: templates/createOrEdit.html:57
msgid "New choice"
msgstr "Nouveau choix"
-#: templates/createOrEdit.html:61
+#: templates/createOrEdit.html:60
msgid "Create"
msgstr "Créer"
@@ -145,44 +153,34 @@ msgstr ""
"Créer un nouveau sondage pour prendre une décision, trouver une date pour "
"une réunion, etc."
-#: polls/models.py:21
+#: polls/models.py:38
msgid "Available"
msgstr "Disponible"
-#: polls/models.py:22
+#: polls/models.py:39
msgid "Disabled"
msgstr "Indisponible"
-#: polls/models.py:24
-msgid "Meeting"
-msgstr "Réunion"
-
-#: polls/models.py:25
+#: polls/models.py:45
msgid "Poll"
msgstr "Sondage"
-#: polls/models.py:26
+#: polls/models.py:46
msgid "Balanced poll"
msgstr "Sondage pondéré"
-#: polls/models.py:47
-msgid "No"
-msgstr "Non"
-
-#: polls/models.py:48
+#: polls/models.py:67
msgid "Maybe"
msgstr "Peut-être"
-#: polls/models.py:49
-msgid "Yes"
-msgstr "Oui"
-
-#: polls/views.py:32
+#: polls/views.py:59
msgid "The poll requested don't exist (anymore?)"
msgstr "Le sondage que vous avez demandé n'existe pas (n'existe plus ?)"
-#: polls/views.py:66
+#: polls/views.py:93
#, python-format
msgid "%s is a mandatory field"
msgstr "%s est un champs obligatoire"
+#~ msgid "Meeting"
+#~ msgstr "Réunion"
diff --git a/polls/models.py b/polls/models.py
index f4f1147..fd5f0a9 100644
--- a/polls/models.py
+++ b/polls/models.py
@@ -28,6 +28,7 @@ class PollUser(models.Model):
name = models.CharField(maxlength=100)
email = models.CharField(maxlength=100)
password = models.CharField(maxlength=100)
+ modification_date = models.DateTimeField(auto_now=True)
class Poll(models.Model):
name = models.CharField(maxlength=200)
@@ -35,35 +36,46 @@ class Poll(models.Model):
author = models.ForeignKey(PollUser)
base_url = models.CharField(maxlength=100)
admin_url = models.CharField(maxlength=100)
+ modification_date = models.DateTimeField(auto_now=True)
STATUS = (('A', _('Available')),
('D', _('Disabled')),)
status = models.CharField(maxlength=1, choices=STATUS)
- """TYPE = (('M', _('Meeting')),
- ('P', _('Poll')),
- ('B', _('Balanced poll')),
- ('O', _('One choice poll')),)"""
TYPE = (('P', _('Poll')),
- ('B', _('Balanced poll')),)
+ ('B', _('Balanced poll')),
+ ('O', _('One choice poll')),)
+ # ('M', _('Meeting')),)
type = models.CharField(maxlength=1, choices=TYPE)
def getTypeLabel(self):
idx = [type[0] for type in self.TYPE].index(self.type)
return Poll.TYPE[idx][1]
-
class Admin:
pass
+ class Meta:
+ ordering = ['-modification_date']
+
+class Voter(models.Model):
+ user = models.ForeignKey(PollUser)
+ poll = models.ForeignKey(Poll)
+ creation_date = models.DateTimeField(auto_now_add=True)
+ class Meta:
+ ordering = ['creation_date']
class Choice(models.Model):
poll = models.ForeignKey(Poll)
name = models.CharField(maxlength=200)
order = models.IntegerField()
+ limit = models.IntegerField()
+ available = models.BooleanField(default=True)
class Admin:
pass
+ class Meta:
+ ordering = ['order']
class Vote(models.Model):
- voter = models.ForeignKey(PollUser)
+ voter = models.ForeignKey(Voter)
choice = models.ForeignKey(Choice)
- VOTE = ((1, _('Yes')),
- (0, _('Maybe')),
- (-1, _('No')),)
- value = models.IntegerField(choices=VOTE) \ No newline at end of file
+ VOTE = ((1, (_('Yes'), _('Yes'))),
+ (0, (_('No'), _('Maybe')), ),
+ (-1, (_('No'), _('No'))),)
+ value = models.IntegerField(choices=VOTE, null=True) \ No newline at end of file
diff --git a/polls/views.py b/polls/views.py
index 771396a..e341654 100644
--- a/polls/views.py
+++ b/polls/views.py
@@ -30,7 +30,7 @@ from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from papillon.settings import LANGUAGES
-from papillon.polls.models import Poll, PollUser, Choice, Vote
+from papillon.polls.models import Poll, PollUser, Choice, Voter, Vote
def getBaseResponse(request):
"""Manage basic fields for the template
@@ -109,7 +109,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type'])
url = response_dct['admin_url'] + '/%s/' % poll.admin_url
return response_dct, HttpResponseRedirect(url)
- def getExistingPoll(request, response_dct, admin_url):
+ def getAndUpdateExistingPoll(request, response_dct, admin_url):
"Get an existing poll"
try:
poll = Poll.objects.filter(admin_url=admin_url)[0]
@@ -117,6 +117,16 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type'])
# if the poll don't exist redirect to the creation page
url = response_dct['admin_url'] + '/0/'
return response_dct, HttpResponseRedirect(url)
+ # update the poll
+ updated = None
+ if 'poll_name' in request.POST and request.POST['poll_name']:
+ updated = True
+ poll.name = request.POST['poll_name']
+ if 'poll_desc' in request.POST and request.POST['poll_desc']:
+ updated = True
+ poll.description = request.POST['poll_desc']
+ if updated:
+ poll.save()
# base feed of the template
new_dct = {'author_name':poll.author.name,
'poll_name':poll.name,
@@ -143,8 +153,15 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type'])
order += 1
except IndexError:
order = 0
+ limit = None
+ if 'limit' in request.POST:
+ try:
+ limit = int(request.POST['limit'])
+ except ValueError:
+ # non numeric limit given : no limit set
+ pass
choice = Choice(poll=poll, name=request.POST['new_choice'],
- order=order)
+ order=order, limit=limit)
choice.save()
# check if a choice has been choosen for deletion
for key in request.POST:
@@ -170,7 +187,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type'])
response_dct['admin_url'] += '/0/'
else:
# existing poll
- response_dct, redirection = getExistingPoll(request,
+ response_dct, redirection = getAndUpdateExistingPoll(request,
response_dct, admin_url)
if redirection:
return redirection
@@ -185,24 +202,51 @@ def poll(request, poll_url):
def modifyVote(request, choices):
"Modify user's votes"
try:
- author = PollUser.objects.filter(
+ voter = Voter.objects.filter(
id=int(request.POST['voter']))[0]
except (ValueError, IndexError):
return
# if no author_name is given deletion of associated votes and
# author
if not request.POST['author_name']:
+ # verify if the author can be deleted
+ delete_user = None
+ if not voter.user.password:
+ v = Voter.objects.filter(user=voter.user)
+ if len(v) == 1 and v[0] == voter:
+ delete_user = voter.user
for choice in choices:
- v = Vote.objects.filter(voter=author, choice=choice)
+ v = Vote.objects.filter(voter=voter, choice=choice)
v.delete()
- author.delete()
+ voter.delete()
+ if delete_user:
+ delete_user.delete()
return
# update the name
- author.name = request.POST['author_name']
- author.save()
+ voter.user.name = request.POST['author_name']
+ voter.user.save()
+ # update the modification date
+ voter.save()
selected_choices = []
# set the selected choices
for key in request.POST:
+ # modify a one choice poll
+ if key == 'vote' and request.POST[key]:
+ try:
+ id = int(request.POST[key])
+ vote = Vote.objects.filter(id=id)[0]
+ if vote.choice not in choices:
+ # bad vote id : the associated choice has
+ # probably been deleted
+ vote.delete()
+ else:
+ vote.value = 1
+ vote.save()
+ selected_choices.append(vote.choice)
+ except (ValueError, IndexError):
+ # the vote don't exist anymore
+ pass
+ # modify an existing vote
if key.startswith('vote_') and request.POST[key]:
try:
id = int(key.split('_')[1])
@@ -224,34 +268,16 @@ def poll(request, poll_url):
except (ValueError, IndexError):
# the vote don't exist anymore
pass
- elif key.startswith('choice_') and request.POST[key]:
- try:
- id = int(key.split('_')[1])
- choice = Choice.objects.filter(id=id)[0]
- if choice not in choices:
- raise ValueError
- # try if a specific value is specified in the form
- # like in balanced poll
- try:
- value = int(request.POST[key])
- except ValueError:
- value = 1
- v = Vote(voter=author, choice=choice, value=value)
- v.save()
- selected_choices.append(choice)
- except (ValueError, IndexError):
- # bad choice id : the choice has probably been deleted
- pass
# update non selected choices
for choice in choices:
if choice not in selected_choices:
try:
- v = Vote.objects.filter(voter=author, choice=choice)[0]
+ v = Vote.objects.filter(voter=voter, choice=choice)[0]
v.value = 0
except IndexError:
# the vote don't exist with this choice : probably
# a new choice
- v = Vote(voter=author, choice=choice, value=0)
+ v = Vote(voter=voter, choice=choice, value=0)
v.save()
def newVote(request, choices):
@@ -260,10 +286,13 @@ def poll(request, poll_url):
return
author = PollUser(name=request.POST['author_name'])
author.save()
+ voter = Voter(user=author, poll=poll)
+ voter.save()
selected_choices = []
# set the selected choices
for key in request.POST:
+ # standard vote
if key.startswith('choice_') and request.POST[key]:
try:
id = int(key.split('_')[1])
@@ -276,7 +305,20 @@ def poll(request, poll_url):
value = int(request.POST[key])
except ValueError:
value = 1
- v = Vote(voter=author, choice=choice, value=value)
+ v = Vote(voter=voter, choice=choice, value=value)
+ v.save()
+ selected_choices.append(choice)
+ except (ValueError, IndexError):
+ # bad choice id : the choice has probably been deleted
+ pass
+ # one choice vote
+ if key == 'choice' and request.POST[key]:
+ try:
+ id = int(request.POST[key])
+ choice = Choice.objects.filter(id=id)[0]
+ if choice not in choices:
+ raise ValueError
+ v = Vote(voter=voter, choice=choice, value=1)
v.save()
selected_choices.append(choice)
except (ValueError, IndexError):
@@ -285,7 +327,7 @@ def poll(request, poll_url):
# set non selected choices
for choice in choices:
if choice not in selected_choices:
- v = Vote(voter=author, choice=choice, value=0)
+ v = Vote(voter=voter, choice=choice, value=0)
v.save()
response_dct, redirect = getBaseResponse(request)
@@ -295,7 +337,7 @@ def poll(request, poll_url):
poll = Poll.objects.filter(base_url=poll_url)[0]
except IndexError:
poll = None
- choices = Choice.objects.filter(poll=poll).order_by('order')
+ choices = list(Choice.objects.filter(poll=poll))
# if the poll don't exist or if it has no choices the user is
# redirected to the main page
if not choices or not poll:
@@ -310,6 +352,8 @@ def poll(request, poll_url):
modifyVote(request, choices)
else:
newVote(request, choices)
+ # update the modification date of the poll
+ poll.save()
# 'voter' is in request.GET when the edit button is pushed
if 'voter' in request.GET:
@@ -318,8 +362,7 @@ def poll(request, poll_url):
except ValueError:
pass
- response_dct.update({'choices':choices,
- 'poll_type_name':poll.getTypeLabel(),
+ response_dct.update({'poll_type_name':poll.getTypeLabel(),
'poll_type':poll.type,
'poll_name':poll.name,
'poll_desc':poll.description,
@@ -328,37 +371,42 @@ def poll(request, poll_url):
+ '/%s/' % poll.base_url
# get voters and sum for each choice for this poll
-
- votes = [] # all votes for this poll
- votes = Vote.objects.extra(where=['choice_id IN (%s)' \
- % ",".join([str(choice.id) for choice in choices])])
-
- voters = []
- choices_sum = [0 for choice in choices]
- choices_ids = [choice.id for choice in choices]
- for vote in votes:
- if vote.voter not in voters:
- # initialize a votes list for the current voter
- vote.voter.votes = [None for choice in choices]
- voters.append(vote.voter)
- voter = vote.voter
- else:
- # get the appropriate voter
- voter = voters[voters.index(vote.voter)]
- idx = choices_ids.index(vote.choice.id)
- # associate vote in the votes list of the voter
- voter.votes[idx] = vote
- choices_sum[idx] += vote.value
- # for undefined vote get the choice id
- # on the template the distinction between the choice and the vote
- # is made by the type of the "vote"
+ voters = Voter.objects.filter(poll=poll)
+ for choice in choices:
+ choice.sum = 0
+ choice_ids = [choice.id for choice in choices]
for voter in voters:
+ query = Vote.objects.filter(voter=voter)
+ query = query.extra(where=['choice_id IN (%s)' \
+ % ",".join([str(choice.id) for choice in choices])])
+ voter.votes = list(query.order_by('choice'))
for vote in voter.votes:
- if not vote:
- idx = voter.votes.index(vote)
- voter.votes[idx] = choices[idx].id
- response_dct.update({'voters':voters,
- 'voter':voters,
- 'choices_sum':[str(sum) for sum in choices_sum]
- })
+ if vote.choice.id in choice_ids:
+ if vote.value:
+ choices[choice_ids.index(vote.choice.id)].sum += vote.value
+ else:
+ # the choice is probably not available anymore
+ voter.votes.remove(vote)
+ vote.delete()
+ # initialize undefined vote
+ choice_vote_ids = [vote.choice.id for vote in voter.votes]
+ for choice in choices:
+ if choice.id not in choice_vote_ids:
+ vote = Vote(voter=voter, choice=choice, value=None)
+ vote.save()
+ idx = choices.index(choice)
+ voter.votes.insert(idx, vote)
+
+ # set non-available choices if the limit is reached for a choice
+ response_dct['limit_set'] = None
+ for choice in choices:
+ if choice.limit:
+ response_dct['limit_set'] = True
+ if choice.limit and choice.sum >= choice.limit:
+ choice.available = False
+ else:
+ choice.available = True
+ choice.save()
+ response_dct['voters'] = voters
+ response_dct['choices'] = choices
return render_to_response('vote.html', response_dct)
diff --git a/static/styles.css b/static/styles.css
index 4079271..1dbc988 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2008 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+Copyright (C) 2008 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@@ -102,7 +102,11 @@ color:red;
}
#new_poll input{
-width:130px;
+width:100px;
+}
+
+#new_poll input#limit{
+width:20px;
}
#new_poll textarea{
diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html
index 4eecaa2..0c223ff 100644
--- a/templates/createOrEdit.html
+++ b/templates/createOrEdit.html
@@ -7,58 +7,73 @@
{% endif %}
<h2>{% if new %}{% trans "New poll" %}{% else %}{% trans "Edit poll" %}{% endif %}</h2>
{% if error %}<p class='error'>{{ error }}</p>{% endif %}
- <form action="{{admin_url}}" method="post">
- <table id='new_poll'>
+<table id='new_poll'>
+<form action="{{admin_url}}" method="post">
{% if not new %}<tr>
<td><label>{% trans "Poll url" %}</label></td>
- <td><a href='http://{{full_base_url}}'>http://{{full_base_url}}</a></td>
+ <td colspan='2'><a href='http://{{full_base_url}}'>http://{{full_base_url}}</a></td>
<td class='form_description'>{% trans "Copy this address and send it to voters who want to participate to this poll" %}</td>
</tr>
<tr>
<td><label>{% trans "Administration url" %}</label></td>
- <td><a href='http://{{full_admin_url}}'>http://{{full_admin_url}}</a></td>
+ <td colspan='2'><a href='http://{{full_admin_url}}'>http://{{full_admin_url}}</a></td>
<td class='form_description'>{% trans "Address to modify the current poll" %}</td>
</tr>
{% endif %}<tr>
<td><label for='author_name'>{% trans "Author name" %}</label></td>
- <td>{% if new %}<input type='text' name='author_name' value='{{author_name}}'/>{% else %}{{author_name}}{% endif %}</td>
+ <td colspan='2'>{% if new %}<input type='text' name='author_name' value='{{author_name}}'/>{% else %}{{author_name}}{% endif %}</td>
<td class='form_description'>{% trans "Name, firstname or nickname of the author" %}</td>
</tr>
<tr>
<td><label for='poll_name'>{% trans "Poll name" %}</label></td>
- <td>{% if new %}<input type='text' name='poll_name' value='{{poll_name}}'/>{% else %}{{poll_name}}{% endif %}</td>
+ <td colspan='2'>{% if new %}<input type='text' name='poll_name' value='{{poll_name}}'/>{% else %}<input type='text' name='poll_name' value='{{poll_name}}'/>{% endif %}</td>
<td class='form_description'>{% trans "Global name to present the poll" %}</td>
</tr>
<tr>
<td><label for='poll_desc'>{% trans "Poll description" %}</label></td>
- <td>{% if new %}<textarea name='poll_desc'>{{poll_desc}}</textarea>{% else %}{{poll_desc}}{% endif %}</td>
+ <td colspan='2'>{% if new %}<textarea name='poll_desc'>{{poll_desc}}</textarea>{% else %}<textarea name='poll_desc'>{{poll_desc}}</textarea>{% endif %}</td>
<td class='form_description'>{% trans "Precise description of the poll" %}</td>
</tr>
<tr>
<td><label for='poll_type'>{% trans "Poll type" %}</label></td>
- <td>{% if new %}<select name='poll_type'>
+ <td colspan='2'>{% if new %}<select name='poll_type'>
{% for typ in TYPES %}<option value='{{typ.0}}'{% ifequal poll_type typ.0%} selected='selected'{% endifequal %}>{{typ.1}}</option>{% endfor %}
</select>{% else %}{{type_name}}{% endif %}</td>
<td class='form_description'>{% trans "Type of the poll:" %}
<ul>
<!--<li>{% trans "Meeting is the appropriate type to set a date for a meeting."%}</li>!-->
- <li>{% trans "Poll is the appropriate type for a simple multi-choice poll" %}</li>
- <li>{% trans "Balanced poll lets voters setting negative vote for some choices" %}</li>
- <!--<li>{% trans "One choice poll" %}</li>!-->
+ <li>{% trans '"Poll" is the appropriate type for a simple multi-choice poll' %}</li>
+ <li>{% trans '"Balanced poll" lets voters setting negative vote for some choices' %}</li>
+ <li>{% trans '"One choice poll"' %}</li>
</ul>
</td>
</tr>
- {% if not new %}{% if choices %}<tr>
- <th>{% trans "Choices" %}</th><th>&nbsp;</th><th>{% trans "Delete?"%}</th>
+ {% if choices %}<tr>
+ <th>{% trans "Choices" %}</th><th>{% trans "Label" %}</th><th>{% trans "Limit" %}</th><th>{% trans "Delete?"%}</th>
</tr>
{% for choice in choices %}<tr>
- <td>&nbsp;</td><td>{{choice.name}}</td><td><input type='checkbox' name='delete_{{choice.id}}'/></td>
+ <td>&nbsp;</td><td>{{choice.name}}</td><td>{%if choice.limit%}{% blocktrans with choice.limit as choice_limit%}Limited to {{choice_limit}} vote(s){% endblocktrans %}{%endif%}</td><td><input type='checkbox' name='delete_{{choice.id}}'/></td>
+ </tr>
+ {% endfor %}{% endif %}
+ <tr>
+ <td></td>
+ <td>{% if new %}<input type='hidden' name='new' value='1'/>
+ <input type='submit' value='{% trans "Create" %}' />
+ {% else %}<input type='hidden' name='edit' value='1'/>
+ <input type='submit' value='{% trans "Edit" %}' />
+ {% endif %}</td>
</tr>
- {% endfor %}{% endif %}<tr><td><label>{% trans "New choice" %}</label></td><td><input type='text' name='new_choice'/></td></tr>
- {% endif %}</table>
- {% if new %}<input type='hidden' name='new' value='1'/>
- <input type='submit' value='{% trans "Create" %}' />
- {% else %}<input type='hidden' name='edit' value='1'/>
- <input type='submit' value='{% trans "Edit" %}' />
- {% endif %}</form>
+ </form>
+{% if new %}
+</table>
+{% else %}
+ <form action="{{admin_url}}" method="post">
+ <tr><td><label>{% trans "New choice" %}</label></td><td><input type='text' name='new_choice'/></td><td>{%trans "Limited to"%} <input type='text' name='limit' id='limit'/> {%trans "vote(s)"%}</td><td class='form_description'>{% trans "Setting a new choice. Optionally you can set a limit of vote for this choice. This limit is usefull for limited resources allocation." %}</td></tr>
+ <tr>
+ <td></td>
+ <td><input type='hidden' name='add' value='1'/> <input type='submit' value='{% trans "Add" %}' /></td>
+ </tr>
+ </form>
+</table>
+ {% endif %}
{% endblock %}
diff --git a/templates/vote.html b/templates/vote.html
index 27e54a3..566bb8e 100644
--- a/templates/vote.html
+++ b/templates/vote.html
@@ -11,32 +11,40 @@
<tr>
<td class='simple'></td>
<td class='simple'></td>
- {% for choice in choices %}<th>{{choice.name}}</th>
+ {% for choice in choices %}<th>{{choice.name}}{% if choice.limit %} ({% trans "max" %} {{choice.limit}}){%endif%}</th>
{% endfor %}</tr>
{% for voter in voters %}<tr>{% ifequal current_voter_id voter.id %}
<input type='hidden' name='voter' value='{{voter.id}}'/>
<td class='simple'></td>
- <td><input type='text' name='author_name' value='{{voter.name}}'/></td>
+ <td><input type='text' name='author_name' value='{{voter.user.name}}'/></td>
{% for vote in voter.votes %}<td>
+ {% if vote.choice.available or vote.value %}
{% ifequal poll_type 'P' %}
- <input type='checkbox' name='{%if vote.id%}vote_{{vote.id}}{%else%}choice_{{vote}}{%endif%}'{%ifequal vote.value 1%} checked='checked'{%endifequal%}/>
+ <input type='checkbox' name='vote_{{vote.id}}'{%ifequal vote.value 1%} checked='checked'{%endifequal%}/>
+ {% endifequal %}
+ {% ifequal poll_type 'O' %}
+ <input type='radio' name='vote' value='{{vote.id}}' {%ifequal vote.value 1%} checked='checked'{%endifequal%}/>
{% endifequal %}
{% ifequal poll_type 'B' %}
- <select name='{%if vote.id%}vote_{{vote.id}}{%else%}choice_{{vote}}{%endif%}'>
+ <select name='vote_{{vote.id}}'>
{% for vote_choice in VOTE %}
<option value='{{vote_choice.0}}'{%ifequal vote.value vote_choice.0%} selected='selected'{%endifequal%}>{{vote_choice.1}}</option>
{% endfor %}
</select>
{% endifequal %}
+ {% else %}
+ {% trans "Limit reached" %}
+ {% endif %}
</td>{%endfor%}
{%else%}<td class='simple'><a href='?voter={{voter.id}}'>{% trans "Edit" %}</a></td>
- <td>{{voter.name}}</td>
+ <td>{{voter.user.name}}</td>
{% for vote in voter.votes %}<td class='{%ifequal vote.value 1%}OK{%else%}{%ifequal vote.value 0%}OKO{%else%}KO{%endifequal%}{%endifequal%}'>
- {%ifequal poll_type 'P'%}
- {%ifequal vote.value 0%}{% trans "No" %}{%else%}{% trans "Yes" %}{%endifequal%}
+ {%ifequal poll_type 'B'%}
+ {%for VOT in VOTE%}
+ {%ifequal VOT.0 vote.value%}{{VOT.1.1}}{%endifequal%}{%endfor%}
{%else%}
{%for VOT in VOTE%}
- {%ifequal VOT.0 vote.value%}{{VOT.1}}{%endifequal%}{%endfor%}
+ {%ifequal VOT.0 vote.value%}{{VOT.1.0}}{%endifequal%}{%endfor%}
{%endifequal%}
</td>
{%endfor%}
@@ -47,19 +55,25 @@
<td class='simple'></td>
<td><input type='text' name='author_name'/></td>
{%for choice in choices%}<td>
+ {% if choice.available %}
{% ifequal poll_type 'P' %}
<input type='checkbox' name='choice_{{choice.id}}'/>{% endifequal %}
+ {% ifequal poll_type 'O' %}
+ <input type='radio' name='choice' value='{{choice.id}}'/>{% endifequal %}
{% ifequal poll_type 'B' %}
<select name='choice_{{choice.id}}'>{% for vote_choice in VOTE %}
- <option value='{{vote_choice.0}}'{%ifequal vote_choice.0 0%} selected='selected'{%endifequal%}>{{vote_choice.1}}</option>{% endfor %}
+ <option value='{{vote_choice.0}}'{%ifequal vote_choice.0 0%} selected='selected'{%endifequal%}>{{vote_choice.1.1}}</option>{% endfor %}
</select>
{% endifequal %}
+ {% else %}
+ {% trans "Limit reached" %}
+ {% endif %}
</td>{%endfor%}
</tr>
{%endif%}
<tr id='sum'>
<td class='simple'></td><th>{% trans "Sum" %}</th>
- {% for sum in choices_sum %}<td>{{sum}}</td>
+ {% for choice in choices %}<td>{{choice.sum}}</td>
{% endfor %}
</tr>
</table>