Skip to content

Instantly share code, notes, and snippets.

@insin
Created February 14, 2012 00:02
Show Gist options
  • Save insin/1821617 to your computer and use it in GitHub Desktop.
Save insin/1821617 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') and e.code in self.error_messages:
error_message = self.error_messages[e.code]
default = self.default_error_messages.get(e.code, None)
if not default or error_message != default:
message = error_message
if e.params:
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