From 87a97edd69fe0258e257138b9ebb26fffbfce6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sat, 6 Feb 2016 00:02:22 +0100 Subject: [PATCH] Used 'detail' for all ValidationError messages. See #1946. --- openslides/core/serializers.py | 6 +++--- openslides/core/views.py | 26 +++++++++++++------------- openslides/mediafiles/views.py | 2 +- openslides/motions/serializers.py | 2 +- openslides/users/serializers.py | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/openslides/core/serializers.py b/openslides/core/serializers.py index 65e5133e3..39dfd971a 100644 --- a/openslides/core/serializers.py +++ b/openslides/core/serializers.py @@ -13,12 +13,12 @@ class JSONSerializerField(Field): value is a dictionary with must have a key 'name'. """ if type(data) is not dict: - raise ValidationError('Data must be a dictionary.') + raise ValidationError({'detail': 'Data must be a dictionary.'}) for element in data.values(): if type(element) is not dict: - raise ValidationError('Data must be a dictionary.') + raise ValidationError({'detail': 'Data must be a dictionary.'}) elif element.get('name') is None: - raise ValidationError("Every dictionary must have a key 'name'.") + raise ValidationError({'detail': "Every dictionary must have a key 'name'."}) return data diff --git a/openslides/core/views.py b/openslides/core/views.py index 218e318f6..14331dc0a 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -177,13 +177,13 @@ class ProjectorViewSet(ReadOnlyModelViewSet): of dictionaries to be appended to the projector config entry. """ if not isinstance(request.data, list): - raise ValidationError({'data': 'Data must be a list.'}) + raise ValidationError({'detail': 'Data must be a list.'}) projector_instance = self.get_object() projector_config = projector_instance.config for element in request.data: if element.get('name') is None: - raise ValidationError({'data': 'Invalid projector element. Name is missing.'}) + raise ValidationError({'detail': 'Invalid projector element. Name is missing.'}) projector_config[uuid.uuid4().hex] = element serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False) @@ -200,7 +200,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet): entries are deleted but not entries with stable == True. """ if not isinstance(request.data, list): - raise ValidationError({'data': 'Data must be a list.'}) + raise ValidationError({'detail': 'Data must be a list.'}) projector_instance = self.get_object() projector_config = {} @@ -209,7 +209,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet): projector_config[key] = value for element in request.data: if element.get('name') is None: - raise ValidationError({'data': 'Invalid projector element. Name is missing.'}) + raise ValidationError({'detail': 'Invalid projector element. Name is missing.'}) projector_config[uuid.uuid4().hex] = element serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False) @@ -239,8 +239,8 @@ class ProjectorViewSet(ReadOnlyModelViewSet): } """ if not isinstance(request.data, dict): - raise ValidationError({'data': 'Data must be a dictionary.'}) - error = {'data': 'Data must be a dictionary with UUIDs as keys and dictionaries as values.'} + raise ValidationError({'detail': 'Data must be a dictionary.'}) + error = {'detail': 'Data must be a dictionary with UUIDs as keys and dictionaries as values.'} for key, value in request.data.items(): try: uuid.UUID(hex=str(key)) @@ -253,7 +253,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet): projector_config = projector_instance.config for key, value in request.data.items(): if key not in projector_config: - raise ValidationError({'data': 'Invalid projector element. Wrong UUID.'}) + raise ValidationError({'detail': 'Invalid projector element. Wrong UUID.'}) projector_config[key].update(request.data[key]) serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False) @@ -270,12 +270,12 @@ class ProjectorViewSet(ReadOnlyModelViewSet): that should be deleted. """ if not isinstance(request.data, list): - raise ValidationError({'data': 'Data must be a list of hex UUIDs.'}) + raise ValidationError({'detail': 'Data must be a list of hex UUIDs.'}) for item in request.data: try: uuid.UUID(hex=str(item)) except ValueError: - raise ValidationError({'data': 'Data must be a list of hex UUIDs.'}) + raise ValidationError({'detail': 'Data must be a list of hex UUIDs.'}) projector_instance = self.get_object() projector_config = projector_instance.config @@ -283,7 +283,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet): try: del projector_config[key] except KeyError: - raise ValidationError({'data': 'Invalid UUID.'}) + raise ValidationError({'detail': 'Invalid UUID.'}) serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False) serializer.is_valid(raise_exception=True) @@ -327,11 +327,11 @@ class ProjectorViewSet(ReadOnlyModelViewSet): } """ if not isinstance(request.data, dict): - raise ValidationError({'data': 'Data must be a dictionary.'}) + raise ValidationError({'detail': 'Data must be a dictionary.'}) if (request.data.get('action') not in ('scale', 'scroll') or request.data.get('direction') not in ('up', 'down', 'reset')): - raise ValidationError({'data': "Data must be a dictionary with an action ('scale' or 'scroll') " - "and a direction ('up', 'down' or 'reset')."}) + raise ValidationError({'detail': "Data must be a dictionary with an action ('scale' or 'scroll') " + "and a direction ('up', 'down' or 'reset')."}) projector_instance = self.get_object() if request.data['action'] == 'scale': diff --git a/openslides/mediafiles/views.py b/openslides/mediafiles/views.py index 6c09f0b61..e39ed9339 100644 --- a/openslides/mediafiles/views.py +++ b/openslides/mediafiles/views.py @@ -46,5 +46,5 @@ class MediafileViewSet(ModelViewSet): str(self.request.user.pk) != str(uploader_id)): self.permission_denied(request) if not self.request.data.get('mediafile'): - raise ValidationError({'details': 'You forgot to provide a file.'}) + raise ValidationError({'detail': 'You forgot to provide a file.'}) return super().create(request, *args, **kwargs) diff --git a/openslides/motions/serializers.py b/openslides/motions/serializers.py index a113aab94..9d6ab1266 100644 --- a/openslides/motions/serializers.py +++ b/openslides/motions/serializers.py @@ -27,7 +27,7 @@ def validate_workflow_field(value): Validator to ensure that the workflow with the given id exists. """ if not Workflow.objects.filter(pk=value).exists(): - raise ValidationError(_('Workflow %(pk)d does not exist.') % {'pk': value}) + raise ValidationError({'detail': _('Workflow %(pk)d does not exist.') % {'pk': value}}) class CategorySerializer(ModelSerializer): diff --git a/openslides/users/serializers.py b/openslides/users/serializers.py index 95a86bb79..f8f48ae30 100644 --- a/openslides/users/serializers.py +++ b/openslides/users/serializers.py @@ -69,7 +69,7 @@ class UserFullSerializer(ModelSerializer): Generates the username if it is empty. """ if not (data.get('username') or data.get('first_name') or data.get('last_name')): - raise ValidationError(_('Username, first name and last name can not all be empty.')) + raise ValidationError({'detail': _('Username, first name and last name can not all be empty.')}) # Generate username. But only if it is not set and the serializer is not # called in a PATCH context (partial_update).