Index: newforms/forms.py =================================================================== --- newforms/forms.py (revision 6992) +++ newforms/forms.py (working copy) @@ -11,7 +11,7 @@ from fields import Field from widgets import TextInput, Textarea -from util import flatatt, ErrorDict, ErrorList, ValidationError +from util import flatatt, WarningDict, WarningList, ErrorDict, ErrorList, ValidationError __all__ = ('BaseForm', 'Form') @@ -87,6 +87,13 @@ return self._errors errors = property(_get_errors) + def _get_warnings(self): + "Returns an WarningsDict for the data provided for the form" + if self._warnings is None: + self.full_clean() + return self._warnings + warnings = property(_get_warnings) + def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are @@ -173,6 +180,7 @@ self.cleaned_data. """ self._errors = ErrorDict() + self._warnings = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} @@ -191,6 +199,7 @@ self._errors[name] = e.messages if name in self.cleaned_data: del self.cleaned_data[name] + self._warnings[name] = getattr(field, warnings, []) try: self.cleaned_data = self.clean() except ValidationError, e: Index: newforms/util.py =================================================================== --- newforms/util.py (revision 6992) +++ newforms/util.py (working copy) @@ -49,6 +49,27 @@ def __repr__(self): return repr([force_unicode(e) for e in self]) +class WarningDict(ErrorDict): + """ + A collection of warnings that knows how to display itself in various formats. + + The dictionary keys are the field names, and the values are the warnings. + """ + def as_ul(self): + if not self: return u'' + return mark_safe(u'