Added "published" attribute for poll object. Adjusted assignment

views and templates.
This commit is contained in:
Emanuel Schuetze 2011-09-08 12:30:34 +02:00
parent ab96b32790
commit 5a3f336cdf
6 changed files with 51 additions and 9 deletions

View File

@ -35,14 +35,18 @@
</ol> </ol>
{% endif %} {% endif %}
{% if item.assignment.poll_set.all.count > 0 %} {% with polls|first as firstpoll %}
{% if polls.count > 0 and firstpoll.published %}
<p><br></p> <p><br></p>
<h3>{% trans "Election results" %}</h3> <h3>{% trans "Election results" %}</h3>
<table> <table>
<tr> <tr>
<th>{% trans "Candidates" %}</th> <th>{% trans "Candidates" %}</th>
{% for poll in item.assignment.poll_set.all %} {% for poll in item.assignment.poll_set.all %}
<th><nobr>{{forloop.counter}}. {% trans "ballot" %}</nobr></th> {% if poll.published %}
<th><nobr>{{forloop.counter}}. {% trans "ballot" %}</nobr></th>
{% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
{% for vote in votes %} {% for vote in votes %}
@ -77,17 +81,22 @@
<tr> <tr>
<td>{%trans 'Invalid votes' %}</td> <td>{%trans 'Invalid votes' %}</td>
{% for p in polls %} {% for p in polls %}
{% if p.published %}
<td style="white-space:nowrap;"><img src="/static/images/icons/voting-invalid.png" title="{% trans 'Invalid' %}"> {{ p.votesinvalid }}</td> <td style="white-space:nowrap;"><img src="/static/images/icons/voting-invalid.png" title="{% trans 'Invalid' %}"> {{ p.votesinvalid }}</td>
{% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
<tr class="total"> <tr class="total">
<td><b>{%trans 'Votes cast' %}</b></td> <td><b>{%trans 'Votes cast' %}</b></td>
{% for p in polls %} {% for p in polls %}
{% if p.published %}
<td style="white-space:nowrap;"><img src="/static/images/icons/voting-total.png" title="{% trans 'Votes cast' %}"> <b>{{ p.votescast }}</b></td> <td style="white-space:nowrap;"><img src="/static/images/icons/voting-total.png" title="{% trans 'Votes cast' %}"> <b>{{ p.votescast }}</b></td>
{% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
</table> </table>
{% endif %} {% endif %}
{% endwith %}
<br> <br>
{% endblock %} {% endblock %}

View File

@ -115,14 +115,15 @@ def assignment_votes(item):
for candidate in assignment.candidates: for candidate in assignment.candidates:
tmplist = [[candidate, assignment.is_elected(candidate)], []] tmplist = [[candidate, assignment.is_elected(candidate)], []]
for poll in assignment.poll_set.all(): for poll in assignment.poll_set.all():
if candidate in poll.options_values: if poll.published:
option = Option.objects.filter(poll=poll).filter(user=candidate)[0] if candidate in poll.options_values:
if poll.optiondecision: option = Option.objects.filter(poll=poll).filter(user=candidate)[0]
tmplist[1].append([option.yes, option.no, option.undesided]) if poll.optiondecision:
tmplist[1].append([option.yes, option.no, option.undesided])
else:
tmplist[1].append(option.yes)
else: else:
tmplist[1].append(option.yes) tmplist[1].append("-")
else:
tmplist[1].append("-")
votes.append(tmplist) votes.append(tmplist)
return votes return votes

View File

@ -130,6 +130,11 @@
{% if perms.assignment.can_manage_assignment %} {% if perms.assignment.can_manage_assignment %}
</a> </a>
<a href="{% url assignment_poll_delete poll.id %}"><img src="/static/images/icons/edit-delete.png" title="{% trans 'Delete Poll' %}"></a> <a href="{% url assignment_poll_delete poll.id %}"><img src="/static/images/icons/edit-delete.png" title="{% trans 'Delete Poll' %}"></a>
{% if poll.published %}
<a href={% url assignment_poll_notpublish poll.id %}>unpublish</a>
{% else %}
<a href={% url assignment_poll_publish poll.id %}>publish</a>
{% endif %}
{% endif %} {% endif %}
</th> </th>
{% endfor %} {% endfor %}

View File

@ -58,6 +58,12 @@ urlpatterns = patterns('assignment.views',
url(r'^assignment/poll/(?P<poll_id>\d+)/del$', 'delete_poll', \ url(r'^assignment/poll/(?P<poll_id>\d+)/del$', 'delete_poll', \
name='assignment_poll_delete'), name='assignment_poll_delete'),
url(r'^assignment/poll/(?P<poll_id>\d+)/pub/$', 'set_published', {'published': True},
name='assignment_poll_publish'),
url(r'^assignment/poll/(?P<poll_id>\d+)/notpub/$', 'set_published', {'published': False},
name='assignment_poll_notpublish'),
url(r'^assignment/(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$', 'set_elected', {'elected': True}, \ url(r'^assignment/(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$', 'set_elected', {'elected': True}, \
name='assignment_user_elected'), name='assignment_user_elected'),

View File

@ -234,6 +234,19 @@ def poll_view(request, poll_id):
'ballotnumber': ballotnumber, 'ballotnumber': ballotnumber,
} }
@permission_required('assignment.can_manage_assignment')
def set_published(request, poll_id, published=True):
try:
poll = Poll.objects.get(pk=poll_id)
print poll.published
poll.set_published(published)
if poll.published:
messages.success(request, _("Poll successfully set to published.") )
else:
messages.success(request, _("Poll successfully set to unpublished.") )
except Poll.DoesNotExist:
messages.error(request, _('Poll ID %d does not exist.') % int(poll_id))
return redirect(reverse('assignment_view', args=[poll.id]))
@permission_required('assignment.can_manage_assignment') @permission_required('assignment.can_manage_assignment')
def delete_poll(request, poll_id): def delete_poll(request, poll_id):

View File

@ -25,6 +25,7 @@ class Poll(models.Model):
description = models.TextField(null=True, blank=True, verbose_name = _("Description")) description = models.TextField(null=True, blank=True, verbose_name = _("Description"))
votescast = models.IntegerField(null=True, blank=True, verbose_name = _("Votes cast")) votescast = models.IntegerField(null=True, blank=True, verbose_name = _("Votes cast"))
votesinvalid = models.IntegerField(null=True, blank=True, verbose_name = _("Votes invalid")) votesinvalid = models.IntegerField(null=True, blank=True, verbose_name = _("Votes invalid"))
published = models.BooleanField(default=False)
def add_option(self, option): def add_option(self, option):
self.save() self.save()
@ -56,6 +57,13 @@ class Poll(models.Model):
def options_values(self): def options_values(self):
return [option.value for option in self.options] return [option.value for option in self.options]
def set_published(self, published=True):
"""
Changes the published-status of the poll.
"""
self.published = published
self.save()
@property @property
def count_ballots(self): def count_ballots(self):
if self.application: if self.application: