Skip to content

Instantly share code, notes, and snippets.

@SmileyChris
Forked from insin/fields.py
Created February 14, 2012 00:04
Show Gist options
  • Save SmileyChris/1821636 to your computer and use it in GitHub Desktop.
Save SmileyChris/1821636 to your computer and use it in GitHub Desktop.
Formatting horrible if
def run_validators(self, value):
if value in validators.EMPTY_VALUES:
return
errors = []
for v in self.validators:
try:
v(value)
except ValidationError, e:
message = None
if hasattr(e, 'code'):
messages = self.default_error_messages.copy()
messages.update(self.error_messages)
message = messages.get(e.code, '')
if getattr(e, 'params', None):
message = message % e.params
if message:
errors.append(message)
else:
errors.extend(e.messages)
if errors:
raise ValidationError(errors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment