Merge pull request #91 from WimpyAnalytics/django110_boundfield

Context not being flattened for bound fields
This commit is contained in:
tzangms 2017-04-30 11:10:47 -05:00 committed by GitHub
commit e47e202841
5 changed files with 24 additions and 12 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ docs/_build
.cache
.tox
.python-version
.idea

View File

@ -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)

View File

@ -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'])

View File

@ -34,6 +34,9 @@ settings.configure(
SITE_ID=1,
DEBUG=False,
ROOT_URLCONF='',
TEMPLATES = [ # For >= Django 1.10
{'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True},
]
)

View File

@ -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