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 .cache
.tox .tox
.python-version .python-version
.idea

View File

@ -6,6 +6,7 @@ from django.test import TestCase
from django.template import Template, Context from django.template import Template, Context
from django import forms from django import forms
from .templatetags import bootstrap
TEST_DIR = os.path.abspath(os.path.join(__file__, '..')) TEST_DIR = os.path.abspath(os.path.join(__file__, '..'))
@ -23,15 +24,15 @@ except:
pass pass
class ExampleForm(forms.Form): class ExampleForm(forms.Form):
char_field = forms.CharField() char_field = forms.CharField(required=False)
choice_field = forms.ChoiceField(choices=CHOICES) choice_field = forms.ChoiceField(choices=CHOICES, required=False)
radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect) radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect, required=False)
multiple_choice = forms.MultipleChoiceField(choices=CHOICES) multiple_choice = forms.MultipleChoiceField(choices=CHOICES, required=False)
multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple) multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple, required=False)
file_fied = forms.FileField() file_fied = forms.FileField(required=False)
password_field = forms.CharField(widget=forms.PasswordInput) password_field = forms.CharField(widget=forms.PasswordInput, required=False)
textarea = forms.CharField(widget=forms.Textarea) textarea = forms.CharField(widget=forms.Textarea, required=False)
boolean_field = forms.BooleanField() boolean_field = forms.BooleanField(required=False)
class BootstrapTemplateTagTests(TestCase): class BootstrapTemplateTagTests(TestCase):
@ -73,3 +74,9 @@ class BootstrapTemplateTagTests(TestCase):
content = f.read() content = f.read()
self.assertHTMLEqual(html, content) 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, SITE_ID=1,
DEBUG=False, DEBUG=False,
ROOT_URLCONF='', ROOT_URLCONF='',
TEMPLATES = [ # For >= Django 1.10
{'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True},
]
) )

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = {py27,py34}-dj{15,16,17,18,19} envlist = {py27,py34}-dj{15,16,17,18,19,110}
skipsdist=True skipsdist=True
@ -14,6 +14,7 @@ deps =
dj17: django>=1.7,<1.8 dj17: django>=1.7,<1.8
dj18: django>=1.8,<1.9 dj18: django>=1.8,<1.9
dj19: django>=1.9,<1.10 dj19: django>=1.9,<1.10
dj110: django>=1.10,<1.11
commands = python setup.py test commands = python setup.py test