Changeset 6273
- Timestamp:
- 09/15/07 05:12:05 (10 months ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/newforms/forms.py (modified) (1 diff)
- django/trunk/django/newforms/widgets.py (modified) (2 diffs)
- django/trunk/docs/newforms.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r6269 r6273 196 196 masonsimon+django@gmail.com 197 197 Manuzhai 198 Petr Marhoun <petr.marhoun@gmail.com> 198 199 Petar MariÄ <http://www.petarmaric.com/> 199 200 Nuno Mariz <nmariz@gmail.com> django/trunk/django/newforms/forms.py
r6156 r6273 213 213 return self.cleaned_data 214 214 215 def is_multipart(self): 216 """ 217 Returns True if the form needs to be multipart-encrypted, i.e. it has 218 FileInput. Otherwise, False. 219 """ 220 for field in self.fields.values(): 221 if field.widget.needs_multipart_form: 222 return True 223 return False 224 215 225 class Form(BaseForm): 216 226 "A collection of Fields, plus their associated data." django/trunk/django/newforms/widgets.py
r5819 r6273 25 25 class Widget(object): 26 26 is_hidden = False # Determines whether this corresponds to an <input type="hidden">. 27 needs_multipart_form = False # Determines does this widget need multipart-encrypted form 27 28 28 29 def __init__(self, attrs=None): … … 121 122 class FileInput(Input): 122 123 input_type = 'file' 124 needs_multipart_form = True 123 125 124 126 def render(self, name, value, attrs=None): django/trunk/docs/newforms.txt
r6196 r6273 776 776 # Unbound form with a image field 777 777 >>> f = ContactFormWithMugshot() 778 779 Testing for multipart forms 780 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 781 782 If you're writing some reusable views or templates, you may not know ahead of 783 time whether your form is a multipart form or not. The ``is_multipart()`` 784 method tells you if the form requires multipart encoding for submission:: 785 786 >>> f = ContactFormWithMugshot() 787 >>> f.is_multipart() 788 True 789 790 In a template, this sort of code could be useful:: 791 792 {% if form.is_multipart %} 793 <form enctype="multipart/form-data" method="post" action="/foo/"> 794 {% else %} 795 <form method="post" action="/foo/"> 796 {% endif %} 797 {% form %} 798 </form> 778 799 779 800 Subclassing forms django/trunk/tests/regressiontests/forms/tests.py
r6173 r6273 3857 3857 <p>Comment: <input type="text" name="comment" /></p> 3858 3858 3859 ################################# 3860 # Test multipart-encoded form # 3861 ################################# 3862 3863 >>> class FormWithoutFile(Form): 3864 ... username = CharField() 3865 >>> class FormWithFile(Form): 3866 ... username = CharField() 3867 ... file = FileField() 3868 >>> class FormWithImage(Form): 3869 ... image = ImageField() 3870 3871 >>> FormWithoutFile().is_multipart() 3872 False 3873 >>> FormWithFile().is_multipart() 3874 True 3875 >>> FormWithImage().is_multipart() 3876 True 3877 3859 3878 """ 3860 3879
