Context not being flattened for bound fields
This commit is contained in:
parent
3b685646ac
commit
69789af0ff
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ docs/_build
|
||||
.cache
|
||||
.tox
|
||||
.python-version
|
||||
.idea
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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'])
|
||||
|
@ -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,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user