Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19545 -- Make sure media/is_multipart work with empty formsets

  • Loading branch information...
commit 3fc43c964ef7ab52261ec3a164d66b19f06f5cea 1 parent 9b5f64c
Simon Charette charettes authored claudep committed
7 django/forms/
@@ -333,7 +333,10 @@ def is_multipart(self):
Returns True if the formset needs to be multipart, i.e. it
has FileInput. Otherwise, False.
- return self.forms and self.forms[0].is_multipart()
+ if self.forms:
+ return self.forms[0].is_multipart()
+ else:
+ return self.empty_form.is_multipart()
def media(self):
@@ -342,7 +345,7 @@ def media(self):
if self.forms:
return self.forms[0].media
- return Media()
+ return
def as_table(self):
"Returns this formset rendered as HTML <tr>s -- excluding the <table></table>."
19 tests/regressiontests/forms/tests/
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.forms import Form, CharField, IntegerField, ValidationError, DateField
-from django.forms.formsets import formset_factory, BaseFormSet
+from django.forms import (CharField, DateField, FileField, Form, IntegerField,
+ ValidationError)
+from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.util import ErrorList
from django.test import TestCase
@@ -974,11 +975,23 @@ def test_empty_forms_are_unbound(self):
self.assertHTMLEqual(empty_forms[0].as_p(), empty_forms[1].as_p())
class TestEmptyFormSet(TestCase):
- "Test that an empty formset still calls clean()"
def test_empty_formset_is_valid(self):
+ """Test that an empty formset still calls clean()"""
EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate)
formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form")
formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form")
+ def test_empty_formset_media(self):
+ """Make sure media is available on empty formset, refs #19545"""
+ class MediaForm(Form):
+ class Media:
+ js = ('some-file.js',)
+ self.assertIn('some-file.js', str(formset_factory(MediaForm, extra=0)().media))
+ def test_empty_formset_is_multipart(self):
+ """Make sure `is_multipart()` works with empty formset, refs #19545"""
+ class FileForm(Form):
+ file = FileField()
+ self.assertTrue(formset_factory(FileForm, extra=0)().is_multipart())
Please sign in to comment.
Something went wrong with that request. Please try again.