summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-02-23 15:39:20 -0800
committerTim Graham <timograham@gmail.com>2016-02-24 07:09:08 -0500
commit6c48edae769dee8c6b691cea525f85f40760d9d0 (patch)
tree4bd8c9723850e7a428113586f3c636bc49a1ce93
parent751e5fcaf7b1824c67676e8bfa6989872457bbbf (diff)
downloaddjango-6c48edae769dee8c6b691cea525f85f40760d9d0.tar.gz
[1.8.x] Fixed #26267 -- Fixed BoundField to reallow slices of subwidgets.
Backport of b41268135995cef46d40e550f9301fab20cf330d from master
-rw-r--r--django/forms/forms.py2
-rw-r--r--docs/releases/1.8.10.txt2
-rw-r--r--docs/spelling_wordlist1
-rw-r--r--tests/forms_tests/tests/test_forms.py14
4 files changed, 18 insertions, 1 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 80ba830684..3f9d7898c2 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -554,7 +554,7 @@ class BoundField(object):
def __getitem__(self, idx):
# Prevent unnecessary reevaluation when accessing BoundField's attrs
# from templates.
- if not isinstance(idx, six.integer_types):
+ if not isinstance(idx, six.integer_types + (slice,)):
raise TypeError
return list(self.__iter__())[idx]
diff --git a/docs/releases/1.8.10.txt b/docs/releases/1.8.10.txt
index b63ae2abdc..c9fbd0470d 100644
--- a/docs/releases/1.8.10.txt
+++ b/docs/releases/1.8.10.txt
@@ -24,3 +24,5 @@ Bugfixes
* Reallowed dashes in top-level domain names of URLs checked by
``URLValidator`` to fix a regression in Django 1.8 (:ticket:`26204`).
+
+* Fixed ``BoundField`` to reallow slices of subwidgets (:ticket:`26267`).
diff --git a/docs/spelling_wordlist b/docs/spelling_wordlist
index c46d6d6e67..0bbc5ec2a6 100644
--- a/docs/spelling_wordlist
+++ b/docs/spelling_wordlist
@@ -512,6 +512,7 @@ quoteless
Radziej
rc
readded
+reallow
reallowed
rebase
rebased
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 7ab1f45da1..c252a17c5b 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -468,6 +468,20 @@ class FormsTestCase(TestCase):
f = BeatleForm(auto_id=False)
self.assertHTMLEqual('\n'.join(str(bf) for bf in f['name']), '<input type="text" name="name" />')
+ def test_boundfield_slice(self):
+ class BeatleForm(Form):
+ name = ChoiceField(
+ choices=[('john', 'John'), ('paul', 'Paul'), ('george', 'George'), ('ringo', 'Ringo')],
+ widget=RadioSelect,
+ )
+
+ f = BeatleForm()
+ bf = f['name']
+ self.assertEqual(
+ [str(item) for item in bf[1:]],
+ [str(bf[1]), str(bf[2]), str(bf[3])],
+ )
+
def test_forms_with_multiple_choice(self):
# MultipleChoiceField is a special case, as its data is required to be a list:
class SongForm(Form):