delete list of speaker error messages (closes #2237)
This commit is contained in:
parent
3b58c76287
commit
929a7e5e89
@ -127,15 +127,22 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV
|
|||||||
self.permission_denied(request)
|
self.permission_denied(request)
|
||||||
if type(speaker_ids) is int:
|
if type(speaker_ids) is int:
|
||||||
speaker_ids = [speaker_ids]
|
speaker_ids = [speaker_ids]
|
||||||
|
deleted_speaker_count = 0
|
||||||
for speaker_id in speaker_ids:
|
for speaker_id in speaker_ids:
|
||||||
try:
|
try:
|
||||||
speaker = Speaker.objects.get(pk=int(speaker_id))
|
speaker = Speaker.objects.get(pk=int(speaker_id))
|
||||||
except (ValueError, Speaker.DoesNotExist):
|
except (ValueError, Speaker.DoesNotExist):
|
||||||
raise ValidationError({'detail': _('Speaker does not exist.')})
|
pass
|
||||||
# Delete the speaker.
|
else:
|
||||||
speaker.delete()
|
speaker.delete()
|
||||||
message = _('Speaker %s was successfully removed from the list of speakers.') % speaker
|
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.
|
# Initiate response.
|
||||||
return Response({'detail': message})
|
return Response({'detail': message})
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.utils.translation import ugettext
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APIClient
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
@ -203,13 +204,17 @@ class ManageSpeaker(TestCase):
|
|||||||
response = self.client.delete(
|
response = self.client.delete(
|
||||||
reverse('item-manage-speaker', args=[self.item.pk]),
|
reverse('item-manage-speaker', args=[self.item.pk]),
|
||||||
{'speaker': '1'})
|
{'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):
|
def test_remove_someone_else_invalid_data(self):
|
||||||
response = self.client.delete(
|
response = self.client.delete(
|
||||||
reverse('item-manage-speaker', args=[self.item.pk]),
|
reverse('item-manage-speaker', args=[self.item.pk]),
|
||||||
{'speaker': 'invalid'})
|
{'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):
|
def test_remove_someone_else_non_admin(self):
|
||||||
admin = get_user_model().objects.get(username='admin')
|
admin = get_user_model().objects.get(username='admin')
|
||||||
|
Loading…
Reference in New Issue
Block a user