diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-15 10:12:05 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-15 10:12:05 +0000 |
| commit | f0cd172cd0bccc519a6ecdf41b6a10b46ccffbcf (patch) | |
| tree | 062ffc271ea2f0c1e308f5e1245129efff856dba /django/newforms | |
| parent | 32ed883861ecded14e51dd8b72d097bc37572c6c (diff) | |
Fixed #5387 -- Added is_multipart method to forms. Original patch from Petr Marhhoun. Tests and documentation from Murkt.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6273 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms')
| -rw-r--r-- | django/newforms/forms.py | 10 | ||||
| -rw-r--r-- | django/newforms/widgets.py | 2 |
2 files changed, 12 insertions, 0 deletions
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/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) |
