#253 don't show unpublished polls for nonmanager in assignment view

This commit is contained in:
Oskar Hahn 2012-07-04 16:05:31 +02:00
parent 47ff052c22
commit ef5b9e3281
2 changed files with 35 additions and 28 deletions

View File

@ -128,16 +128,19 @@ class Assignment(models.Model, SlideMixin):
continue continue
vote_results_dict[candidate] = [] vote_results_dict[candidate] = []
for poll in polls: for poll in polls:
votes = {
'votes': {},
'published': poll.published,
}
try: try:
polloption = poll.get_options().get(candidate=candidate) # candidate related to this poll
# candidate is related to this poll poll_option = poll.get_options().get(candidate=candidate)
votes = {} for vote in poll_option.get_votes():
for vote in polloption.get_votes(): votes['votes'][vote.value] = vote.get_weight()
votes[vote.value] = vote.get_weight()
vote_results_dict[candidate].append(votes)
except AssignmentOption.DoesNotExist: except AssignmentOption.DoesNotExist:
# candidate not in related to this poll # candidate not in related to this poll
vote_results_dict[candidate].append(None) votes['votes'] = None
vote_results_dict[candidate].append(votes)
return vote_results_dict return vote_results_dict

View File

@ -99,7 +99,7 @@
{% if polls %} {% if polls %}
<table id="election_table" style="width: auto;"> <table id="election_table" style="width: auto;">
<tr> <tr>
<th></th> <th></th>
{% with ballotnumber=polls.count %} {% with ballotnumber=polls.count %}
@ -108,7 +108,7 @@
</th> </th>
{% endwith %} {% endwith %}
</tr> </tr>
<tr> <tr>
<th>{% trans "Candidates" %}</th> <th>{% trans "Candidates" %}</th>
{% for poll in polls %} {% for poll in polls %}
@ -138,15 +138,18 @@
</th> </th>
{% endif %} {% endif %}
</tr> </tr>
{% for candidate, votes in vote_results.items %} {% for candidate, poll_list in vote_results.items %}
<tr class="{% cycle 'odd' '' %}"> <tr class="{% cycle 'odd' '' %}">
<td class="candidate"> <td class="candidate">
{% if candidate in assignment.elected.all %} {% if candidate in assignment.elected.all %}
{% if perms.assignment.can_manage_assignment %} {% if perms.assignment.can_manage_assignment %}
{# What does this line do #}
<a class="election_link elected" href='{% url assignment_user_not_elected assignment.id candidate.id %}'></a> <a class="election_link elected" href='{% url assignment_user_not_elected assignment.id candidate.id %}'></a>
{% else %} {% else %}
<a class="elected"><img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Candidate is elected' %}"></a> <a class="elected">
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Candidate is elected' %}">
</a>
{% endif %} {% endif %}
{% else %} {% else %}
{% if perms.assignment.can_manage_assignment %} {% if perms.assignment.can_manage_assignment %}
@ -155,21 +158,22 @@
{% endif %} {% endif %}
{{ candidate }} {{ candidate }}
</td> </td>
{% for vote in votes %} {% for poll_dict in poll_list %}
{% if perms.assignment.can_manage_assignment %} {% if perms.assignment.can_manage_assignment or poll_dict.published %}
{# Hier stimmt es noch nicht. Es muss rein, dass veröffentlichte Wahlergebnisse für jedermann sichtbar sind #}
<td style="white-space:nowrap;"> <td style="white-space:nowrap;">
{% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %} {% with vote=poll_dict.votes %}
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Yes }}<br> {% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %}
<img src="{% static 'images/icons/voting-no.png' %}" title="{% trans 'No' %}"> {{ vote.No }}<br> <img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Yes }}<br>
<img src="{% static 'images/icons/voting-abstention.png' %}" title="{% trans 'Abstention' %}"> {{ vote.Abstain }}<br> <img src="{% static 'images/icons/voting-no.png' %}" title="{% trans 'No' %}"> {{ vote.No }}<br>
{% elif 'Votes' in vote %} <img src="{% static 'images/icons/voting-abstention.png' %}" title="{% trans 'Abstention' %}"> {{ vote.Abstain }}<br>
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Votes }} {% elif 'Votes' in vote %}
{% elif vote == None %} <img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Votes }}
{% trans 'was not a <br> candidate'%} {% elif vote == None %}
{% else %} {% trans 'was not a <br> candidate'%}
&nbsp; {% else %}
{% endif %} &nbsp;
{% endif %}
{% endwith %}
</td> </td>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -178,7 +182,7 @@
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
<tr> <tr>
<td>{%trans 'Invalid votes' %}</td> <td>{%trans 'Invalid votes' %}</td>
{% for poll in polls %} {% for poll in polls %}
@ -190,7 +194,7 @@
<td></td> <td></td>
{% endif %} {% endif %}
</tr> </tr>
<tr class="total"> <tr class="total">
<td><strong>{%trans 'Votes cast' %}</strong></td> <td><strong>{%trans 'Votes cast' %}</strong></td>
{% for poll in polls %} {% for poll in polls %}