diff options
| author | Honza Král <honza.kral@gmail.com> | 2009-06-01 15:38:11 +0000 |
|---|---|---|
| committer | Honza Král <honza.kral@gmail.com> | 2009-06-01 15:38:11 +0000 |
| commit | 55e23d5efaa11b7385c9c0d117378b07cdeb7341 (patch) | |
| tree | 3f256f30b15ca2212bb248bf06d484fa73481aa3 /django/core | |
| parent | a2b215263596b1778054e3e8710dd6da13063f16 (diff) | |
[soc2009/model-validation] Moved ValidationError to django.core.exceptions and removed ErrorList from within the Error
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10867 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/exceptions.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/django/core/exceptions.py b/django/core/exceptions.py index 1c21031739..2fe384e6dd 100644 --- a/django/core/exceptions.py +++ b/django/core/exceptions.py @@ -34,4 +34,21 @@ class FieldError(Exception): class ValidationError(Exception): """An error while validating data.""" - pass + def __init__(self, message): + from django.utils.encoding import force_unicode + """ + ValidationError can be passed any object that can be printed (usually + a string) or a list of objects. + """ + if isinstance(message, list): + self.messages = [force_unicode(msg) for msg in message] + else: + message = force_unicode(message) + self.messages = [message] + + def __str__(self): + # This is needed because, without a __str__(), printing an exception + # instance would result in this: + # AttributeError: ValidationError instance has no attribute 'args' + # See http://www.python.org/doc/current/tut/node10.html#handling + return repr(self.messages) |
