diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:57:25 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:57:25 +0000 |
| commit | ca33d307dee3cf68cc9cd2ccfae00c7ff23ea890 (patch) | |
| tree | e0f0afa392f4ab50de4a89e2a0b1b4cc53f40794 /django/newforms | |
| parent | 7325fbf4ff20f9b0f21d3a1aba1abaca78a765d7 (diff) | |
queryset-refactor: Merged to [6300]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6340 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms')
| -rw-r--r-- | django/newforms/fields.py | 8 | ||||
| -rw-r--r-- | django/newforms/forms.py | 10 | ||||
| -rw-r--r-- | django/newforms/util.py | 11 | ||||
| -rw-r--r-- | django/newforms/widgets.py | 2 |
4 files changed, 24 insertions, 7 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py index d83cb6cde2..8fb1d4f392 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -144,7 +144,7 @@ class IntegerField(Field): if value in EMPTY_VALUES: return None try: - value = int(value) + value = int(str(value)) except (ValueError, TypeError): raise ValidationError(ugettext(u'Enter a whole number.')) if self.max_value is not None and value > self.max_value: @@ -192,7 +192,7 @@ class DecimalField(Field): super(DecimalField, self).clean(value) if not self.required and value in EMPTY_VALUES: return None - value = value.strip() + value = str(value).strip() try: value = Decimal(value) except DecimalException: @@ -452,6 +452,10 @@ class BooleanField(Field): def clean(self, value): "Returns a Python boolean object." super(BooleanField, self).clean(value) + # Explicitly check for the string '0', which is what as hidden field + # will submit for False. + if value == '0': + return False return bool(value) class NullBooleanField(BooleanField): diff --git a/django/newforms/forms.py b/django/newforms/forms.py index ab8729be65..2b1caddeda 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -212,6 +212,16 @@ class BaseForm(StrAndUnicode): """ return self.cleaned_data + def is_multipart(self): + """ + Returns True if the form needs to be multipart-encrypted, i.e. it has + FileInput. Otherwise, False. + """ + for field in self.fields.values(): + if field.widget.needs_multipart_form: + return True + return False + class Form(BaseForm): "A collection of Fields, plus their associated data." # This is a separate class from BaseForm in order to abstract the way diff --git a/django/newforms/util.py b/django/newforms/util.py index 57995bebd0..e19d894397 100644 --- a/django/newforms/util.py +++ b/django/newforms/util.py @@ -1,5 +1,5 @@ from django.utils.html import escape -from django.utils.encoding import smart_unicode, StrAndUnicode +from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode from django.utils.functional import Promise def flatatt(attrs): @@ -22,10 +22,10 @@ class ErrorDict(dict, StrAndUnicode): def as_ul(self): if not self: return u'' - return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, smart_unicode(v)) for k, v in self.items()]) + return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, force_unicode(v)) for k, v in self.items()]) def as_text(self): - return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u' * %s' % smart_unicode(i) for i in v])) for k, v in self.items()]) + return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u' * %s' % force_unicode(i) for i in v])) for k, v in self.items()]) class ErrorList(list, StrAndUnicode): """ @@ -36,11 +36,11 @@ class ErrorList(list, StrAndUnicode): def as_ul(self): if not self: return u'' - return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % smart_unicode(e) for e in self]) + return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % force_unicode(e) for e in self]) def as_text(self): if not self: return u'' - return u'\n'.join([u'* %s' % smart_unicode(e) for e in self]) + return u'\n'.join([u'* %s' % force_unicode(e) for e in self]) class ValidationError(Exception): def __init__(self, message): @@ -58,3 +58,4 @@ class ValidationError(Exception): # AttributeError: ValidationError instance has no attribute 'args' # See http://www.python.org/doc/current/tut/node10.html#handling return repr(self.messages) + diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py index f985124389..0e7752499e 100644 --- a/django/newforms/widgets.py +++ b/django/newforms/widgets.py @@ -24,6 +24,7 @@ __all__ = ( class Widget(object): is_hidden = False # Determines whether this corresponds to an <input type="hidden">. + needs_multipart_form = False # Determines does this widget need multipart-encrypted form def __init__(self, attrs=None): if attrs is not None: @@ -120,6 +121,7 @@ class MultipleHiddenInput(HiddenInput): class FileInput(Input): input_type = 'file' + needs_multipart_form = True def render(self, name, value, attrs=None): return super(FileInput, self).render(name, None, attrs=attrs) |
