Skip to content

Commit 69789af

Browse files
committed
Context not being flattened for bound fields
1 parent 3b68564 commit 69789af

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ docs/_build
88
.cache
99
.tox
1010
.python-version
11+
.idea

bootstrapform/templatetags/bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def render(element, markup_classes):
7777
template = get_template("bootstrapform/form.html")
7878
context = Context({'form': element, 'classes': markup_classes})
7979

80-
if django_version >= (1, 8):
81-
context = context.flatten()
80+
if django_version >= (1, 8):
81+
context = context.flatten()
8282

8383
return template.render(context)
8484

bootstrapform/tests.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.template import Template, Context
77
from django import forms
88

9+
from .templatetags import bootstrap
910

1011
TEST_DIR = os.path.abspath(os.path.join(__file__, '..'))
1112

@@ -23,15 +24,15 @@
2324
pass
2425

2526
class ExampleForm(forms.Form):
26-
char_field = forms.CharField()
27-
choice_field = forms.ChoiceField(choices=CHOICES)
28-
radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect)
29-
multiple_choice = forms.MultipleChoiceField(choices=CHOICES)
30-
multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple)
31-
file_fied = forms.FileField()
32-
password_field = forms.CharField(widget=forms.PasswordInput)
33-
textarea = forms.CharField(widget=forms.Textarea)
34-
boolean_field = forms.BooleanField()
27+
char_field = forms.CharField(required=False)
28+
choice_field = forms.ChoiceField(choices=CHOICES, required=False)
29+
radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect, required=False)
30+
multiple_choice = forms.MultipleChoiceField(choices=CHOICES, required=False)
31+
multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple, required=False)
32+
file_fied = forms.FileField(required=False)
33+
password_field = forms.CharField(widget=forms.PasswordInput, required=False)
34+
textarea = forms.CharField(widget=forms.Textarea, required=False)
35+
boolean_field = forms.BooleanField(required=False)
3536

3637

3738
class BootstrapTemplateTagTests(TestCase):
@@ -73,3 +74,9 @@ def test_horizontal_form(self):
7374
content = f.read()
7475

7576
self.assertHTMLEqual(html, content)
77+
78+
def test_bound_field(self):
79+
form = ExampleForm(data={'char_field': 'asdf'})
80+
81+
self.assertTrue(form.is_bound)
82+
rendered_template = bootstrap.bootstrap(form['char_field'])

runtests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
SITE_ID=1,
3535
DEBUG=False,
3636
ROOT_URLCONF='',
37+
TEMPLATES = [ # For >= Django 1.10
38+
{
39+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
40+
'APP_DIRS': True,
41+
},
42+
]
3743
)
3844

3945

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = {py27,py34}-dj{15,16,17,18,19}
2+
envlist = {py27,py34}-dj{15,16,17,18,19,110}
33
skipsdist=True
44

55

@@ -14,6 +14,7 @@ deps =
1414
dj17: django>=1.7,<1.8
1515
dj18: django>=1.8,<1.9
1616
dj19: django>=1.9,<1.10
17+
dj110: django>=1.10,<1.11
1718
commands = python setup.py test
1819

1920

0 commit comments

Comments
 (0)