equal
deleted
inserted
replaced
1 from django.utils.html import conditional_escape |
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 from django.utils.safestring import mark_safe |
3 from django.utils.safestring import mark_safe |
|
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 |
4 |
8 |
5 def flatatt(attrs): |
9 def flatatt(attrs): |
6 """ |
10 """ |
7 Convert a dictionary of attributes to a single string. |
11 Convert a dictionary of attributes to a single string. |
8 The returned string will contain a leading space followed by key="value", |
12 The returned string will contain a leading space followed by key="value", |
46 return u'\n'.join([u'* %s' % force_unicode(e) for e in self]) |
50 return u'\n'.join([u'* %s' % force_unicode(e) for e in self]) |
47 |
51 |
48 def __repr__(self): |
52 def __repr__(self): |
49 return repr([force_unicode(e) for e in self]) |
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) |
|