diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 2b0360d9a..0b98490d4 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -127,15 +127,22 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV self.permission_denied(request) if type(speaker_ids) is int: speaker_ids = [speaker_ids] + deleted_speaker_count = 0 for speaker_id in speaker_ids: try: speaker = Speaker.objects.get(pk=int(speaker_id)) except (ValueError, Speaker.DoesNotExist): - raise ValidationError({'detail': _('Speaker does not exist.')}) - # Delete the speaker. - speaker.delete() - message = _('Speaker %s was successfully removed from the list of speakers.') % speaker - + pass + else: + speaker.delete() + deleted_speaker_name = speaker + deleted_speaker_count += 1 + if deleted_speaker_count > 1: + message = str(deleted_speaker_count) + ' ' + _('speakers have been removed from the list of speakers.') + elif deleted_speaker_count == 1: + message = _('User %s has been removed from the list of speakers.') % deleted_speaker_name + else: + message = _('No speakers have been removed from the list of speakers.') # Initiate response. return Response({'detail': message}) diff --git a/tests/integration/agenda/test_viewset.py b/tests/integration/agenda/test_viewset.py index 01c87ae95..1083d7c35 100644 --- a/tests/integration/agenda/test_viewset.py +++ b/tests/integration/agenda/test_viewset.py @@ -1,5 +1,6 @@ from django.contrib.auth import get_user_model from django.core.urlresolvers import reverse +from django.utils.translation import ugettext from rest_framework import status from rest_framework.test import APIClient @@ -203,13 +204,17 @@ class ManageSpeaker(TestCase): response = self.client.delete( reverse('item-manage-speaker', args=[self.item.pk]), {'speaker': '1'}) - self.assertEqual(response.status_code, 400) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data.get('detail'), + ugettext('No speakers have been removed from the list of speakers.')) def test_remove_someone_else_invalid_data(self): response = self.client.delete( reverse('item-manage-speaker', args=[self.item.pk]), {'speaker': 'invalid'}) - self.assertEqual(response.status_code, 400) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data.get('detail'), + ugettext('No speakers have been removed from the list of speakers.')) def test_remove_someone_else_non_admin(self): admin = get_user_model().objects.get(username='admin')