From 69789af0ffe4c7952ed288b62a602b779da7b76e Mon Sep 17 00:00:00 2001 From: Ivan VenOsdel Date: Sun, 11 Sep 2016 09:29:41 -0500 Subject: [PATCH] Context not being flattened for bound fields --- .gitignore | 1 + bootstrapform/templatetags/bootstrap.py | 4 ++-- bootstrapform/tests.py | 25 ++++++++++++++++--------- runtests.py | 6 ++++++ tox.ini | 3 ++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 10730ca..e29a071 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ docs/_build .cache .tox .python-version +.idea diff --git a/bootstrapform/templatetags/bootstrap.py b/bootstrapform/templatetags/bootstrap.py index c720db8..71512aa 100644 --- a/bootstrapform/templatetags/bootstrap.py +++ b/bootstrapform/templatetags/bootstrap.py @@ -77,8 +77,8 @@ def render(element, markup_classes): template = get_template("bootstrapform/form.html") context = Context({'form': element, 'classes': markup_classes}) - if django_version >= (1, 8): - context = context.flatten() + if django_version >= (1, 8): + context = context.flatten() return template.render(context) diff --git a/bootstrapform/tests.py b/bootstrapform/tests.py index 74d8b15..f56f39b 100644 --- a/bootstrapform/tests.py +++ b/bootstrapform/tests.py @@ -6,6 +6,7 @@ from django.test import TestCase from django.template import Template, Context from django import forms +from .templatetags import bootstrap TEST_DIR = os.path.abspath(os.path.join(__file__, '..')) @@ -23,15 +24,15 @@ except: pass class ExampleForm(forms.Form): - char_field = forms.CharField() - choice_field = forms.ChoiceField(choices=CHOICES) - radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect) - multiple_choice = forms.MultipleChoiceField(choices=CHOICES) - multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple) - file_fied = forms.FileField() - password_field = forms.CharField(widget=forms.PasswordInput) - textarea = forms.CharField(widget=forms.Textarea) - boolean_field = forms.BooleanField() + char_field = forms.CharField(required=False) + choice_field = forms.ChoiceField(choices=CHOICES, required=False) + radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect, required=False) + multiple_choice = forms.MultipleChoiceField(choices=CHOICES, required=False) + multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple, required=False) + file_fied = forms.FileField(required=False) + password_field = forms.CharField(widget=forms.PasswordInput, required=False) + textarea = forms.CharField(widget=forms.Textarea, required=False) + boolean_field = forms.BooleanField(required=False) class BootstrapTemplateTagTests(TestCase): @@ -73,3 +74,9 @@ class BootstrapTemplateTagTests(TestCase): content = f.read() self.assertHTMLEqual(html, content) + + def test_bound_field(self): + form = ExampleForm(data={'char_field': 'asdf'}) + + self.assertTrue(form.is_bound) + rendered_template = bootstrap.bootstrap(form['char_field']) diff --git a/runtests.py b/runtests.py index 0efa252..53d0a97 100644 --- a/runtests.py +++ b/runtests.py @@ -34,6 +34,12 @@ settings.configure( SITE_ID=1, DEBUG=False, ROOT_URLCONF='', + TEMPLATES = [ # For >= Django 1.10 + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + }, + ] ) diff --git a/tox.ini b/tox.ini index 52bff21..360df6d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py27,py34}-dj{15,16,17,18,19} +envlist = {py27,py34}-dj{15,16,17,18,19,110} skipsdist=True @@ -14,6 +14,7 @@ deps = dj17: django>=1.7,<1.8 dj18: django>=1.8,<1.9 dj19: django>=1.9,<1.10 + dj110: django>=1.10,<1.11 commands = python setup.py test