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>
{% endif %}
{% if item.assignment.poll_set.all.count > 0 %}
{% with polls|first as firstpoll %}
{% if polls.count > 0 and firstpoll.published %}
<p><br></p>
<h3>{% trans "Election results" %}</h3>
<table>
<tr>
<th>{% trans "Candidates" %}</th>
{% 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 %}
</tr>
{% for vote in votes %}
@ -77,17 +81,22 @@
<tr>
<td>{%trans 'Invalid votes' %}</td>
{% 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>
{% endif %}
{% endfor %}
</tr>
<tr class="total">
<td><b>{%trans 'Votes cast' %}</b></td>
{% 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>
{% endif %}
{% endfor %}
</tr>
</table>
{% endif %}
{% endwith %}
<br>
{% endblock %}

View File

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

View File

@ -130,6 +130,11 @@
{% if perms.assignment.can_manage_assignment %}
</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 %}
</th>
{% endfor %}

View File

@ -58,6 +58,12 @@ urlpatterns = patterns('assignment.views',
url(r'^assignment/poll/(?P<poll_id>\d+)/del$', 'delete_poll', \
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}, \
name='assignment_user_elected'),

View File

@ -234,6 +234,19 @@ def poll_view(request, poll_id):
'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')
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"))
votescast = models.IntegerField(null=True, blank=True, verbose_name = _("Votes cast"))
votesinvalid = models.IntegerField(null=True, blank=True, verbose_name = _("Votes invalid"))
published = models.BooleanField(default=False)
def add_option(self, option):
self.save()
@ -56,6 +57,13 @@ class Poll(models.Model):
def options_values(self):
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
def count_ballots(self):
if self.application: