Added error message if a new candidate is already nominated.
This commit is contained in:
parent
a8e7ee40ad
commit
91174afa99
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user