fusionbox/django-fusionbox — pull request #22 by colinta (2012-02-16 03:29:14+00:00)
Title: Validation Behavior

Adds the following methods:

* `validation`: For custom model validation. Raise a `ValidationError` in this method to add generic error messages.
* `validation_{{field}}`: For custom field validation. Raise a `ValidationError` to add error messages that get associated with `{{field}}`.
* `is_valid`: Returns True or False. Internally calls `return not self.validation_errors()`
* `validation_errors`: Returns a dict of errors if a ValidationErrors is thrown (not the ValidationError object). Generic errors are in `django.core.exceptions.NON_FIELD_ERRORS` (aka `__all__`).

Overrides `Model.save` to ensure that `full_clean` is run, so calling `save` on a Validation model ensures that a valid object is saved. ValidationErrors are not caught. Calling `full_clean` ensures that not just custom validation, but built-in validation is performed as well.

Also includes a test and documentation (docstrings).

Since `ValidationErrors` are not usually thrown in `Model.save`, this *could* have unintended side-effects. It shouldn't have any effect in places where a `Form` is used to validate the object before saving.