From 91174afa994246c870c911fc3371332a11f432d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sat, 28 Nov 2015 21:23:21 +0100 Subject: [PATCH] Added error message if a new candidate is already nominated. --- openslides/assignments/views.py | 5 +++-- tests/integration/assignments/test_viewset.py | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openslides/assignments/views.py b/openslides/assignments/views.py index 53acf6033..b2318b6a1 100644 --- a/openslides/assignments/views.py +++ b/openslides/assignments/views.py @@ -162,14 +162,15 @@ class AssignmentViewSet(ModelViewSet): detail = _('You can not nominate someone to this election because it is finished.') raise ValidationError({'detail': detail}) if assignment.phase == assignment.PHASE_VOTING and not request.user.has_perm('assignments.can_manage'): - # To nominate other during voting you have to be a manager. + # To nominate another user during voting you have to be a manager. self.permission_denied(request) if not request.user.has_perm('assignments.can_manage'): if assignment.is_blocked(user): raise ValidationError({'detail': _('User %s does not want to be a candidate. Only a manager can do this.') % user}) if assignment.is_elected(user): raise ValidationError({'detail': _('User %s is already elected.') % user}) - # If the user is already a candidate he can be nominated nevertheless. + if assignment.is_candidate(user): + raise ValidationError({'detail': _('User %s is already nominated.') % user}) assignment.set_candidate(user) return _('User %s was nominated successfully.') % user diff --git a/tests/integration/assignments/test_viewset.py b/tests/integration/assignments/test_viewset.py index 6f8b5d005..06892faee 100644 --- a/tests/integration/assignments/test_viewset.py +++ b/tests/integration/assignments/test_viewset.py @@ -151,8 +151,7 @@ class CandidatureOther(TestCase): reverse('assignment-candidature-other', args=[self.assignment.pk]), {'user': self.user.pk}) - self.assertEqual(response.status_code, 200) - self.assertTrue(Assignment.objects.get(pk=self.assignment.pk).candidates.filter(username='test_user_eeheekai4Phue6cahtho').exists()) + self.assertEqual(response.status_code, 400) def test_nominate_other_when_finished(self): self.assignment.set_phase(Assignment.PHASE_FINISHED)