Ticket #23: warnings_as_list_partial.patch
File warnings_as_list_partial.patch, 2.5 KB (added by , 17 years ago) |
---|
-
newforms/forms.py
11 11 12 12 from fields import Field 13 13 from widgets import TextInput, Textarea 14 from util import flatatt, ErrorDict, ErrorList, ValidationError14 from util import flatatt, WarningDict, WarningList, ErrorDict, ErrorList, ValidationError 15 15 16 16 __all__ = ('BaseForm', 'Form') 17 17 … … 87 87 return self._errors 88 88 errors = property(_get_errors) 89 89 90 def _get_warnings(self): 91 "Returns an WarningsDict for the data provided for the form" 92 if self._warnings is None: 93 self.full_clean() 94 return self._warnings 95 warnings = property(_get_warnings) 96 90 97 def is_valid(self): 91 98 """ 92 99 Returns True if the form has no errors. Otherwise, False. If errors are … … 173 180 self.cleaned_data. 174 181 """ 175 182 self._errors = ErrorDict() 183 self._warnings = ErrorDict() 176 184 if not self.is_bound: # Stop further processing. 177 185 return 178 186 self.cleaned_data = {} … … 191 199 self._errors[name] = e.messages 192 200 if name in self.cleaned_data: 193 201 del self.cleaned_data[name] 202 self._warnings[name] = getattr(field, warnings, []) 194 203 try: 195 204 self.cleaned_data = self.clean() 196 205 except ValidationError, e: -
newforms/util.py
49 49 def __repr__(self): 50 50 return repr([force_unicode(e) for e in self]) 51 51 52 class WarningDict(ErrorDict): 53 """ 54 A collection of warnings that knows how to display itself in various formats. 55 56 The dictionary keys are the field names, and the values are the warnings. 57 """ 58 def as_ul(self): 59 if not self: return u'' 60 return mark_safe(u'<ul class="warninglist">%s</ul>' 61 % ''.join([u'<li>%s%s</li>' % (k, force_unicode(v)) 62 for k, v in self.items()])) 63 64 class WarningList(ErrorList): 65 """ 66 A collection of warnings that knows how to display itself in various formats. 67 """ 68 def as_ul(self): 69 if not self: return u'' 70 return mark_safe(u'<ul class="warninglist">%s</ul>' 71 % ''.join([u'<li>%s</li>' % force_unicode(e) for e in self])) 72 52 73 class ValidationError(Exception): 53 74 def __init__(self, message): 54 75 """