From 98ee433cd344e59b410d3e61772e415f98e7de9b Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 3 Sep 2011 11:56:35 +0200 Subject: [PATCH] merge error --- openslides/assignment/models.py | 8 ++++---- openslides/assignment/views.py | 35 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 3992fbedf..4b0a214a6 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -91,7 +91,7 @@ class Assignment(models.Model): def gen_poll(self): from poll.models import Poll poll = Poll() - + candidates = list(self.profile.all()) for elected in self.elected.all(): try: @@ -104,17 +104,17 @@ class Assignment(models.Model): poll.optiondecision = True else: poll.optiondecision = False - + # Option B: candidates == 1 -> yes/no/abstention #if self.profile.count() == 1: # poll.optiondecision = True #else: # poll.optiondecision = False - + poll.assignment = self poll.description = self.polldescription poll.save() - for candidate in candidates: + for candidate in candidates: poll.add_option(candidate) return poll diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 038e599d7..a415a6395 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -65,24 +65,18 @@ def view(request, assignment_id=None): if request.user.has_perm('assignment.can_nominate_other'): form = AssignmentRunForm() - # list of candidates - candidates = set() - for option in Option.objects.filter(poll__assignment=assignment): - candidates.add(option.value) - votes = [] - for candidate in candidates: - tmplist = [] - tmplist.append(candidate) + 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.append([option.yes, option.no, option.undesided]) + tmplist[1].append([option.yes, option.no, option.undesided]) else: - tmplist.append(option.yes) + tmplist[1].append(option.yes) else: - tmplist.append("-") + tmplist[1].append("-") votes.append(tmplist) return {'assignment': assignment, @@ -241,3 +235,22 @@ def delete_poll(request, poll_id): else: del_confirm_form(request, poll, name=_("the %s. ballot") % ballot) return redirect(reverse('assignment_view', args=[assignment.id])) + +@permission_required('assignment.can_manage_assignment') +def set_elected(request, assignment_id, profile_id, elected=True): + assignment = Assignment.objects.get(pk=assignment_id) + profile = Profile.objects.get(pk=profile_id) + assignment.set_elected(profile, elected) + + if request.is_ajax(): + if elected: + link = reverse('assignment_user_not_elected', args=[assignment.id, profile.id]) + text = _('not elected') + else: + link = reverse('assignment_user_elected', args=[assignment.id, profile.id]) + text = _('elected') + return ajax_request({'elected': elected, + 'link': link, + 'text': text}) + + return redirect(reverse('assignment_view', args=[assignment_id]))