Used 'detail' for all ValidationError messages. See #1946.
This commit is contained in:
parent
378218e8a5
commit
87a97edd69
@ -13,12 +13,12 @@ class JSONSerializerField(Field):
|
|||||||
value is a dictionary with must have a key 'name'.
|
value is a dictionary with must have a key 'name'.
|
||||||
"""
|
"""
|
||||||
if type(data) is not dict:
|
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():
|
for element in data.values():
|
||||||
if type(element) is not dict:
|
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:
|
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
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,13 +177,13 @@ class ProjectorViewSet(ReadOnlyModelViewSet):
|
|||||||
of dictionaries to be appended to the projector config entry.
|
of dictionaries to be appended to the projector config entry.
|
||||||
"""
|
"""
|
||||||
if not isinstance(request.data, list):
|
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_instance = self.get_object()
|
||||||
projector_config = projector_instance.config
|
projector_config = projector_instance.config
|
||||||
for element in request.data:
|
for element in request.data:
|
||||||
if element.get('name') is None:
|
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
|
projector_config[uuid.uuid4().hex] = element
|
||||||
|
|
||||||
serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False)
|
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.
|
entries are deleted but not entries with stable == True.
|
||||||
"""
|
"""
|
||||||
if not isinstance(request.data, list):
|
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_instance = self.get_object()
|
||||||
projector_config = {}
|
projector_config = {}
|
||||||
@ -209,7 +209,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet):
|
|||||||
projector_config[key] = value
|
projector_config[key] = value
|
||||||
for element in request.data:
|
for element in request.data:
|
||||||
if element.get('name') is None:
|
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
|
projector_config[uuid.uuid4().hex] = element
|
||||||
|
|
||||||
serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False)
|
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):
|
if not isinstance(request.data, dict):
|
||||||
raise ValidationError({'data': 'Data must be a dictionary.'})
|
raise ValidationError({'detail': 'Data must be a dictionary.'})
|
||||||
error = {'data': 'Data must be a dictionary with UUIDs as keys and dictionaries as values.'}
|
error = {'detail': 'Data must be a dictionary with UUIDs as keys and dictionaries as values.'}
|
||||||
for key, value in request.data.items():
|
for key, value in request.data.items():
|
||||||
try:
|
try:
|
||||||
uuid.UUID(hex=str(key))
|
uuid.UUID(hex=str(key))
|
||||||
@ -253,7 +253,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet):
|
|||||||
projector_config = projector_instance.config
|
projector_config = projector_instance.config
|
||||||
for key, value in request.data.items():
|
for key, value in request.data.items():
|
||||||
if key not in projector_config:
|
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])
|
projector_config[key].update(request.data[key])
|
||||||
|
|
||||||
serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False)
|
serializer = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False)
|
||||||
@ -270,12 +270,12 @@ class ProjectorViewSet(ReadOnlyModelViewSet):
|
|||||||
that should be deleted.
|
that should be deleted.
|
||||||
"""
|
"""
|
||||||
if not isinstance(request.data, list):
|
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:
|
for item in request.data:
|
||||||
try:
|
try:
|
||||||
uuid.UUID(hex=str(item))
|
uuid.UUID(hex=str(item))
|
||||||
except ValueError:
|
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_instance = self.get_object()
|
||||||
projector_config = projector_instance.config
|
projector_config = projector_instance.config
|
||||||
@ -283,7 +283,7 @@ class ProjectorViewSet(ReadOnlyModelViewSet):
|
|||||||
try:
|
try:
|
||||||
del projector_config[key]
|
del projector_config[key]
|
||||||
except KeyError:
|
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 = self.get_serializer(projector_instance, data={'config': projector_config}, partial=False)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
@ -327,10 +327,10 @@ class ProjectorViewSet(ReadOnlyModelViewSet):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
if not isinstance(request.data, dict):
|
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
|
if (request.data.get('action') not in ('scale', 'scroll') or
|
||||||
request.data.get('direction') not in ('up', 'down', 'reset')):
|
request.data.get('direction') not in ('up', 'down', 'reset')):
|
||||||
raise ValidationError({'data': "Data must be a dictionary with an action ('scale' or 'scroll') "
|
raise ValidationError({'detail': "Data must be a dictionary with an action ('scale' or 'scroll') "
|
||||||
"and a direction ('up', 'down' or 'reset')."})
|
"and a direction ('up', 'down' or 'reset')."})
|
||||||
|
|
||||||
projector_instance = self.get_object()
|
projector_instance = self.get_object()
|
||||||
|
@ -46,5 +46,5 @@ class MediafileViewSet(ModelViewSet):
|
|||||||
str(self.request.user.pk) != str(uploader_id)):
|
str(self.request.user.pk) != str(uploader_id)):
|
||||||
self.permission_denied(request)
|
self.permission_denied(request)
|
||||||
if not self.request.data.get('mediafile'):
|
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)
|
return super().create(request, *args, **kwargs)
|
||||||
|
@ -27,7 +27,7 @@ def validate_workflow_field(value):
|
|||||||
Validator to ensure that the workflow with the given id exists.
|
Validator to ensure that the workflow with the given id exists.
|
||||||
"""
|
"""
|
||||||
if not Workflow.objects.filter(pk=value).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):
|
class CategorySerializer(ModelSerializer):
|
||||||
|
@ -69,7 +69,7 @@ class UserFullSerializer(ModelSerializer):
|
|||||||
Generates the username if it is empty.
|
Generates the username if it is empty.
|
||||||
"""
|
"""
|
||||||
if not (data.get('username') or data.get('first_name') or data.get('last_name')):
|
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
|
# Generate username. But only if it is not set and the serializer is not
|
||||||
# called in a PATCH context (partial_update).
|
# called in a PATCH context (partial_update).
|
||||||
|
Loading…
Reference in New Issue
Block a user