~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/forms/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.utils.html import conditional_escape
2
 
from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode
 
2
from django.utils.encoding import StrAndUnicode, force_unicode
3
3
from django.utils.safestring import mark_safe
4
4
 
 
5
# Import ValidationError so that it can be imported from this
 
6
# module to maintain backwards compatibility.
 
7
from django.core.exceptions import ValidationError
 
8
 
5
9
def flatatt(attrs):
6
10
    """
7
11
    Convert a dictionary of attributes to a single string.
48
52
    def __repr__(self):
49
53
        return repr([force_unicode(e) for e in self])
50
54
 
51
 
class ValidationError(Exception):
52
 
    def __init__(self, message):
53
 
        """
54
 
        ValidationError can be passed any object that can be printed (usually
55
 
        a string) or a list of objects.
56
 
        """
57
 
        if isinstance(message, list):
58
 
            self.messages = ErrorList([smart_unicode(msg) for msg in message])
59
 
        else:
60
 
            message = smart_unicode(message)
61
 
            self.messages = ErrorList([message])
62
 
 
63
 
    def __str__(self):
64
 
        # This is needed because, without a __str__(), printing an exception
65
 
        # instance would result in this:
66
 
        # AttributeError: ValidationError instance has no attribute 'args'
67
 
        # See http://www.python.org/doc/current/tut/node10.html#handling
68
 
        return repr(self.messages)