Created
January 4, 2018 05:05
-
-
Save blackrobot/e5e80ebc7e9432e8c4509857da30e21c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_data(self, data): | |
ret = OrderedDict() | |
errors = OrderedDict() | |
fields = self._writable_fields | |
for field in fields: | |
validate_method = getattr( | |
self, 'validate_' + field.field_name, None) | |
primitive_value = field.get_value(data) | |
try: | |
validated_value = field.run_validation(primitive_value) | |
if validate_method is not None: | |
validated_value = validate_method(validated_value) | |
except ValidationError as exc: | |
errors[field.field_name] = exc.detail | |
except DjangoValidationError as exc: | |
errors[field.field_name] = get_error_detail(exc) | |
except SkipField: | |
pass | |
else: | |
set_value(ret, field.source_attrs, validated_value) | |
if errors: | |
errors['id'] = data['id'] | |
raise ValidationError(errors) | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment