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

View File

@ -88,8 +88,18 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if perms.assignment.can_manage_assignments %}
<p><br></p> <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> <h3>{% trans "Election results" %}</h3>
{% if polls.exists %} {% if polls.exists %}

View File

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