From 0d7ea17c14dacf1c87072e1d082a66f37b1badf9 Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Tue, 1 Jan 2013 05:33:52 -0500
Subject: [PATCH] Fixed #19545 -- Make sure formsets with no extra forms
provide the correct medias
---
django/forms/formsets.py | 2 +-
tests/regressiontests/forms/tests/formsets.py | 9 ++++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 3893cc5..a84d3bc 100644
a
|
b
|
class BaseFormSet(object):
|
344 | 344 | if self.forms: |
345 | 345 | return self.forms[0].media |
346 | 346 | else: |
347 | | return Media() |
| 347 | return self.empty_form.media |
348 | 348 | |
349 | 349 | def as_table(self): |
350 | 350 | "Returns this formset rendered as HTML <tr>s -- excluding the <table></table>." |
diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
index bf893c4..0bee972 100644
a
|
b
|
class TestIsBoundBehavior(TestCase):
|
974 | 974 | self.assertHTMLEqual(empty_forms[0].as_p(), empty_forms[1].as_p()) |
975 | 975 | |
976 | 976 | class TestEmptyFormSet(TestCase): |
977 | | "Test that an empty formset still calls clean()" |
978 | 977 | def test_empty_formset_is_valid(self): |
| 978 | """Test that an empty formset still calls clean()""" |
979 | 979 | EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate) |
980 | 980 | formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form") |
981 | 981 | formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form") |
982 | 982 | self.assertFalse(formset.is_valid()) |
983 | 983 | self.assertFalse(formset2.is_valid()) |
984 | 984 | |
| 985 | def test_empty_formset_media(self): |
| 986 | """Make sure media is available on empty formset, refs #19545""" |
| 987 | class MediaForm(Form): |
| 988 | class Media: |
| 989 | js = ('some-file.js',) |
| 990 | self.assertIn('some-file.js', str(formset_factory(MediaForm, extra=0)().media)) |
| 991 | |