From 50e1e7105e89911b1d6df4534f0ba6c45ccce3aa Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Wed, 2 Jan 2013 14:45:42 -0500
Subject: [PATCH] Make sure `is_multipart` works with empty formsets.
---
django/forms/formsets.py | 5 ++++-
tests/regressiontests/forms/tests/formsets.py | 10 ++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index a84d3bc..8156037 100644
a
|
b
|
class BaseFormSet(object):
|
335 | 335 | Returns True if the formset needs to be multipart, i.e. it |
336 | 336 | has FileInput. Otherwise, False. |
337 | 337 | """ |
338 | | return self.forms and self.forms[0].is_multipart() |
| 338 | if self.forms: |
| 339 | return self.forms[0].is_multipart() |
| 340 | else: |
| 341 | return self.empty_form.is_multipart() |
339 | 342 | |
340 | 343 | @property |
341 | 344 | def media(self): |
diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
index 0bee972..ef6f40c 100644
a
|
b
|
|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from __future__ import unicode_literals |
3 | 3 | |
4 | | from django.forms import Form, CharField, IntegerField, ValidationError, DateField |
5 | | from django.forms.formsets import formset_factory, BaseFormSet |
| 4 | from django.forms import (CharField, DateField, FileField, Form, IntegerField, |
| 5 | ValidationError) |
| 6 | from django.forms.formsets import BaseFormSet, formset_factory |
6 | 7 | from django.forms.util import ErrorList |
7 | 8 | from django.test import TestCase |
8 | 9 | |
… |
… |
class TestEmptyFormSet(TestCase):
|
989 | 990 | js = ('some-file.js',) |
990 | 991 | self.assertIn('some-file.js', str(formset_factory(MediaForm, extra=0)().media)) |
991 | 992 | |
| 993 | def test_empty_formset_is_multipart(self): |
| 994 | """Make sure `is_multipart()` works with empty formset, refs #19545""" |
| 995 | class FileForm(Form): |
| 996 | file = FileField() |
| 997 | self.assertTrue(formset_factory(FileForm, extra=0)().is_multipart()) |