show blocked candidates of an assignment

This commit is contained in:
Oskar Hahn 2012-09-13 14:59:14 +02:00
parent 0725003377
commit e64f4f5efc
3 changed files with 37 additions and 9 deletions

View File

@ -38,6 +38,9 @@ class AssignmentCandidate(models.Model):
def __unicode__(self):
return unicode(self.person)
class Meta:
unique_together = ("assignment", "person")
class Assignment(models.Model, SlideMixin):
prefix = 'assignment'
@ -83,12 +86,13 @@ class Assignment(models.Model, SlideMixin):
if not person.has_perm("assignment.can_manage_assignment") and self.status != 'sea':
raise NameError(_('The candidate list is already closed.'))
candidation = self.assignment_candidats.filter(person=candidate)
if candidation and candidate != person:
if candidation and candidate != person and \
not person.has_perm("assignment.can_manage_assignment"):
# if the candidation is blocked and anotherone tries to run the
# candidate
raise NameError(
_('The %s does not want to be a candidate.') % candidate)
elif candidation and candidate == person:
elif candidation:
candidation[0].blocked = False
candidation[0].save()
else:
@ -98,16 +102,21 @@ class Assignment(models.Model, SlideMixin):
"""
stop running for a vote
"""
if self.is_candidate(candidate):
try:
candidation = self.assignment_candidats.get(person=candidate)
except AssignmentCandidate.DoesNotExist:
# TODO: Use an OpenSlides Error
raise Exception(_('%s is no candidate') % candidate)
if not candidation.blocked:
if blocked:
candidation.blocked = True
candidation.save()
else:
candidation.delete()
else:
# TODO: Use an OpenSlides Error
raise Exception(_('%s is no candidate') % candidate)
candidation.delete()
def is_candidate(self, person):
"""
@ -116,6 +125,13 @@ class Assignment(models.Model, SlideMixin):
return self.assignment_candidats.filter(person=person) \
.exclude(blocked=True).exists()
def is_blocked(self, person):
"""
return True, if the person is blockt for candidation.
"""
return self.assignment_candidats.filter(person=person) \
.filter(blocked=True).exists()
@property
def assignment_candidats(self):
return AssignmentCandidate.objects.filter(assignment=self)

View File

@ -88,8 +88,18 @@
{% endif %}
{% endif %}
<p><br></p>
{% if perms.assignment.can_manage_assignments %}
<h3>{% trans "Blocked Candidates" %}</h3>
<ul>
{% for candidate in blocked_candidates %}
<li>
{{ candidate }}<a href="{% url assignment_delother assignment.id candidate.person_id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Remove candidate' %}"></a>
</li>
{% empty %}
<li>{% trans "There are no blocked candidates." %}</li>
{% endfor %}
</ul>
{% endif %}
<h3>{% trans "Election results" %}</h3>
{% if polls.exists %}

View File

@ -100,13 +100,15 @@ def view(request, assignment_id=None):
polls = assignment.poll_set.all()
vote_results = assignment.vote_results(only_published=False)
blocked_candidates = [candidate.person for candidate in \
assignment.assignment_candidats.filter(blocked=True)]
return {
'assignment': assignment,
'blocked_candidates': blocked_candidates,
'form': form,
'vote_results': vote_results,
'polls': polls,
'user_is_candidate': assignment.is_candidate(request.user)
}
'user_is_candidate': assignment.is_candidate(request.user)}
@permission_required('assignment.can_manage_assignment')