From 95c2f32086b98edcdc1121bb936cfdefa1ee33bf Mon Sep 17 00:00:00 2001 From: etienne Date: Thu, 21 Aug 2008 00:40:10 +0000 Subject: Implementation of the 3 choices poll --- polls/models.py | 13 +++++++------ polls/views.py | 28 ++++++++++++++++++++++++---- templates/createOrEdit.html | 9 ++++----- templates/vote.html | 32 +++++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 18 deletions(-) diff --git a/polls/models.py b/polls/models.py index 2abd4ae..f4f1147 100644 --- a/polls/models.py +++ b/polls/models.py @@ -38,10 +38,12 @@ class Poll(models.Model): STATUS = (('A', _('Available')), ('D', _('Disabled')),) status = models.CharField(maxlength=1, choices=STATUS) - TYPE = (('M', _('Meeting')), + """TYPE = (('M', _('Meeting')), ('P', _('Poll')), ('B', _('Balanced poll')), - ('O', _('One choice poll')),) + ('O', _('One choice poll')),)""" + TYPE = (('P', _('Poll')), + ('B', _('Balanced poll')),) type = models.CharField(maxlength=1, choices=TYPE) def getTypeLabel(self): @@ -61,8 +63,7 @@ class Choice(models.Model): class Vote(models.Model): voter = models.ForeignKey(PollUser) choice = models.ForeignKey(Choice) - VOTE = ((-1, _('No')), + VOTE = ((1, _('Yes')), (0, _('Maybe')), - (1, _('Yes')),) - value = models.IntegerField(choices=VOTE) - + (-1, _('No')),) + value = models.IntegerField(choices=VOTE) \ No newline at end of file diff --git a/polls/views.py b/polls/views.py index bf6320a..771396a 100644 --- a/polls/views.py +++ b/polls/views.py @@ -212,7 +212,13 @@ def poll(request, poll_url): # probably been deleted vote.delete() else: - vote.value = 1 + # try if a specific value is specified in the form + # like in balanced poll + try: + value = int(request.POST[key]) + except ValueError: + value = 1 + vote.value = value vote.save() selected_choices.append(vote.choice) except (ValueError, IndexError): @@ -224,7 +230,13 @@ def poll(request, poll_url): choice = Choice.objects.filter(id=id)[0] if choice not in choices: raise ValueError - v = Vote(voter=author, choice=choice, value=1) + # 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): @@ -258,7 +270,13 @@ def poll(request, poll_url): choice = Choice.objects.filter(id=id)[0] if choice not in choices: raise ValueError - v = Vote(voter=author, choice=choice, value=1) + # 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): @@ -302,8 +320,10 @@ def poll(request, poll_url): response_dct.update({'choices':choices, 'poll_type_name':poll.getTypeLabel(), + 'poll_type':poll.type, 'poll_name':poll.name, - 'poll_desc':poll.description}) + 'poll_desc':poll.description, + 'VOTE':Vote.VOTE,}) response_dct['base_url'] = "/".join(request.path.split('/')[:-2]) \ + '/%s/' % poll.base_url diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html index 12d9d9d..4eecaa2 100644 --- a/templates/createOrEdit.html +++ b/templates/createOrEdit.html @@ -34,21 +34,20 @@ {% if new %}{% else %}{{poll_desc}}{% endif %} {% trans "Precise description of the poll" %} -
  • {% trans "Poll is the appropriate type for a simple multi-choice poll" %}
  • {% trans "Balanced poll lets voters setting negative vote for some choices" %}
  • -
  • {% trans "One choice poll" %}
  • + - !--> - + {% if not new %}{% if choices %} {% trans "Choices" %} {% trans "Delete?"%} diff --git a/templates/vote.html b/templates/vote.html index 0174a18..27e54a3 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -17,10 +17,28 @@ - {% for vote in voter.votes %}{%endfor%} + {% for vote in voter.votes %} + {% ifequal poll_type 'P' %} + + {% endifequal %} + {% ifequal poll_type 'B' %} + + {% endifequal %} + {%endfor%} {%else%}{% trans "Edit" %} {{voter.name}} - {% for vote in voter.votes %}{% ifequal vote.value 1%}Yes{%else%}No{%endifequal%} + {% for vote in voter.votes %} + {%ifequal poll_type 'P'%} + {%ifequal vote.value 0%}{% trans "No" %}{%else%}{% trans "Yes" %}{%endifequal%} + {%else%} + {%for VOT in VOTE%} + {%ifequal VOT.0 vote.value%}{{VOT.1}}{%endifequal%}{%endfor%} + {%endifequal%} + {%endfor%} {%endifequal%} {%endfor%} @@ -28,7 +46,15 @@ - {%for choice in choices%}{%endfor%} + {%for choice in choices%} + {% ifequal poll_type 'P' %} + {% endifequal %} + {% ifequal poll_type 'B' %} + + {% endifequal %} + {%endfor%} {%endif%} -- cgit v1.2.3