From 599c62e4e77aaa4898b9ba690e39b1102ac09a71 Mon Sep 17 00:00:00 2001 From: etienne Date: Sat, 6 Dec 2008 01:21:48 +0000 Subject: Highlight prefered choice - Open/close a poll - Css modification --- polls/models.py | 2 +- polls/views.py | 32 +++++++++++++++++++++----------- static/styles.css | 22 +++++++++++++++------- templates/createOrEdit.html | 29 ++++++++++++++++++----------- templates/vote.html | 31 ++++++++++++++++++------------- 5 files changed, 73 insertions(+), 43 deletions(-) diff --git a/polls/models.py b/polls/models.py index f4cf93a..7128e0d 100644 --- a/polls/models.py +++ b/polls/models.py @@ -90,4 +90,4 @@ class Vote(models.Model): VOTE = ((1, (_('Yes'), _('Yes'))), (0, (_('No'), _('Maybe')), ), (-1, (_('No'), _('No'))),) - value = models.IntegerField(choices=VOTE, blank=True) + value = models.IntegerField(choices=VOTE, blank=True, null=True) diff --git a/polls/views.py b/polls/views.py index 4c6499d..b81e393 100644 --- a/polls/views.py +++ b/polls/views.py @@ -202,9 +202,13 @@ public=public) Vote.objects.filter(choice=choice).delete() choice.delete() if key.startswith('modify_') and request.POST[key]: - choice = Choice.objects.get(id=int(key[len('modify_'):])) - choice.name = request.POST[key] - choice.save() + try: + choice = Choice.objects.get(id=int(key[len('modify_'):])) + choice.name = request.POST[key] + choice.save() + except Choice.DoesNotExist: + # throw when want to modify a deleted choice + pass return response_dct, None response_dct, redirect = getBaseResponse(request) @@ -394,7 +398,7 @@ def poll(request, poll_url): return HttpResponseRedirect(url) # a vote is submitted - if 'author_name' in request.POST: + if 'author_name' in request.POST and poll.open: if 'voter' in request.POST: # modification of an old vote modifyVote(request, choices) @@ -404,17 +408,14 @@ def poll(request, poll_url): poll.save() # 'voter' is in request.GET when the edit button is pushed - if 'voter' in request.GET: + if 'voter' in request.GET and poll.open: try: response_dct['current_voter_id'] = int(request.GET['voter']) except ValueError: pass response_dct.update({'poll_type_name':poll.getTypeLabel(), - 'poll_type':poll.type, - 'poll_name':poll.name, - 'poll_desc':poll.description, - 'poll_base_url':poll.base_url, + 'poll':poll, 'VOTE':Vote.VOTE,}) response_dct['base_url'] = "/".join(request.path.split('/')[:-2]) \ + '/%s/' % poll.base_url @@ -423,6 +424,8 @@ def poll(request, poll_url): voters = Voter.objects.filter(poll=poll) for choice in choices: choice.sum = 0 + max = -100 + max_ids = [] choice_ids = [choice.id for choice in choices] for voter in voters: # highlight a voter @@ -436,7 +439,13 @@ def poll(request, poll_url): for vote in voter.votes: if vote.choice.id in choice_ids: if vote.value: - choices[choice_ids.index(vote.choice.id)].sum += vote.value + c_id = choice_ids.index(vote.choice.id) + choices[c_id].sum += vote.value + if choices[c_id].sum > max: + max_ids = [c_id] + max = choices[c_id].sum + elif choices[c_id].sum == max: + max_ids.append(c_id) else: # the choice is probably not available anymore voter.votes.remove(vote) @@ -449,7 +458,8 @@ def poll(request, poll_url): vote.save() idx = choices.index(choice) voter.votes.insert(idx, vote) - + for max_id in max_ids: + choices[max_id].highlight = True # set non-available choices if the limit is reached for a choice response_dct['limit_set'] = None for choice in choices: diff --git a/static/styles.css b/static/styles.css index 0d44f63..e95cd1e 100644 --- a/static/styles.css +++ b/static/styles.css @@ -138,20 +138,24 @@ color:grey; text-decoration:none; } -.error{ -color:red; +.alert{ +color:blue; } -#new_poll input{ -width:100px; +.new_poll{ +width:600px; +} + +.new_poll input{ +width:160px; } -#new_poll input#limit{ +.new_poll input#limit{ width:20px; } -#new_poll textarea{ -width:130px; +.new_poll textarea{ +width:160px; height:100px; } @@ -221,7 +225,11 @@ text-align:center; #sum td{ border:None; +} + +.highlight{ font-weight:bold; +background-color:#ced3e1; } tr.highlighted_voter td{ diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html index 417f7b7..3e88bfe 100644 --- a/templates/createOrEdit.html +++ b/templates/createOrEdit.html @@ -7,7 +7,7 @@ {% endif %}

{% if new %}{% trans "New poll" %}{% else %}{% trans "Edit poll" %}{% endif %}

{% if error %}

{{ error }}

{% endif %} - +
{% if not new %} @@ -88,14 +88,6 @@ - {% if choices %} - - - {% for choice in choices %} - - - {% endfor %}{% endif %} - -{% if new %}
{% trans "Choices" %}{% trans "Label" %}{% trans "Limit" %}{% trans "Delete?"%}
 {%if choice.limit%}{% blocktrans with choice.limit as choice_limit%}Limited to {{choice_limit}} vote(s){% endblocktrans %}{%endif%}
{% if new %} @@ -106,9 +98,24 @@
-{% else %} +{% if not new %} +

{% trans "Choices" %}

+ + {% if choices %} + + + + {% for choice in choices %} + + {% endfor %} + + + + + {% endif %} + diff --git a/templates/vote.html b/templates/vote.html index e000bc9..803813e 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -2,9 +2,10 @@ {% load i18n %} {% block content %} -

{{poll_type_name}} - {{poll_name}}

-{% if error %}

{{ error }}

{% endif %} -

{{poll_desc}}

+

{{poll_type_name}} - {{poll.name}}

+{% if error %}

{{ error }}

{% endif %} +{% if not poll.open %}

{% trans "The current poll is closed."%}

{% endif %} +

{{ poll.description }}

{% trans "Choices" %}{% trans "Label" %}{% trans "Limit" %}{% trans "Delete?"%}
 {%if choice.limit%}{% blocktrans with choice.limit as choice_limit%}Limited to {{choice_limit}} vote(s){% endblocktrans %}{%endif%}
+
{%trans "Limited to"%} {%trans "vote(s)"%}{% trans "Setting a new choice. Optionally you can set a limit of vote for this choice. This limit is usefull for limited resources allocation." %}
@@ -20,13 +21,13 @@ {% for vote in voter.votes %}{%endfor%} - {%else%} + {%else%} {% for vote in voter.votes %}{%endfor%} {%if not current_voter_id%} + {% if poll.open %} {%for choice in choices%}{%endfor%} {%endif%} + {%endif%} - {% for choice in choices %} + {% for choice in choices %}{{choice.sum}} {% endfor %}
{% if vote.choice.available or vote.value %} - {% ifequal poll_type 'P' %} + {% ifequal poll.type 'P' %} {% endifequal %} - {% ifequal poll_type 'O' %} + {% ifequal poll.type 'O' %} {% endifequal %} - {% ifequal poll_type 'B' %} + {% ifequal poll.type 'B' %} {% trans "Edit" %}{% if poll.open %}{% trans "Edit" %}{%else%} {%endif%} {{voter.user.name}} - {%ifequal poll_type 'B'%} + {%ifequal poll.type 'B'%} {%for VOT in VOTE%} {%ifequal VOT.0 vote.value%}{{VOT.1.1}}{%endifequal%}{%endfor%} {%else%} @@ -52,16 +53,17 @@ {%endifequal%}
{% if choice.available %} - {% ifequal poll_type 'P' %} + {% ifequal poll.type 'P' %} {% endifequal %} - {% ifequal poll_type 'O' %} + {% ifequal poll.type 'O' %} {% endifequal %} - {% ifequal poll_type 'B' %} + {% ifequal poll.type 'B' %} @@ -72,17 +74,20 @@
{% trans "Sum" %}{{choice.sum}}
+ {% if poll.open %} + {% endif %}
- {% trans "Remain informed of poll evolution:" %} {%trans "Syndication"%} + {% trans "Remain informed of poll evolution:" %} {%trans "Syndication"%}
{% endblock %} -- cgit v1.2.3