From e64f4f5efc96baeb328f7d7c5d8c05a955b1c60c Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 13 Sep 2012 14:59:14 +0200 Subject: [PATCH] show blocked candidates of an assignment --- openslides/assignment/models.py | 26 +++++++++++++++---- .../assignment/templates/assignment/view.html | 14 ++++++++-- openslides/assignment/views.py | 6 +++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 7b7064ef1..805913d4e 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -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) diff --git a/openslides/assignment/templates/assignment/view.html b/openslides/assignment/templates/assignment/view.html index fc4feb615..d3414f2a0 100644 --- a/openslides/assignment/templates/assignment/view.html +++ b/openslides/assignment/templates/assignment/view.html @@ -88,8 +88,18 @@ {% endif %} {% endif %} - -


+{% if perms.assignment.can_manage_assignments %} +

{% trans "Blocked Candidates" %}

+ +{% endif %}

{% trans "Election results" %}

{% if polls.exists %} diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 5271750c4..fdd727eda 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -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')