diff options
| author | etienne <etienne@07715635-78ed-41b0-aaf1-0afda6c37f35> | 2008-08-21 00:40:10 +0000 |
|---|---|---|
| committer | etienne <etienne@07715635-78ed-41b0-aaf1-0afda6c37f35> | 2008-08-21 00:40:10 +0000 |
| commit | 95c2f32086b98edcdc1121bb936cfdefa1ee33bf (patch) | |
| tree | 7d6c78b791ba193f10dc972131d9a97fbd65635a /polls | |
| parent | fad8645171c29359ba9ecfc128dceba545298849 (diff) | |
| download | Papillon-95c2f32086b98edcdc1121bb936cfdefa1ee33bf.tar.bz2 Papillon-95c2f32086b98edcdc1121bb936cfdefa1ee33bf.zip | |
Implementation of the 3 choices poll
Diffstat (limited to 'polls')
| -rw-r--r-- | polls/models.py | 13 | ||||
| -rw-r--r-- | polls/views.py | 28 |
2 files changed, 31 insertions, 10 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 |
