Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context not being flattened for bound fields #91

Merged
merged 2 commits into from Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ docs/_build
.cache
.tox
.python-version
.idea
4 changes: 2 additions & 2 deletions bootstrapform/templatetags/bootstrap.py
Expand Up @@ -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)

Expand Down
25 changes: 16 additions & 9 deletions bootstrapform/tests.py
Expand Up @@ -6,6 +6,7 @@
from django.template import Template, Context
from django import forms

from .templatetags import bootstrap

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

Expand All @@ -23,15 +24,15 @@
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):
Expand Down Expand Up @@ -73,3 +74,9 @@ def test_horizontal_form(self):
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'])
3 changes: 3 additions & 0 deletions runtests.py
Expand Up @@ -34,6 +34,9 @@
SITE_ID=1,
DEBUG=False,
ROOT_URLCONF='',
TEMPLATES = [ # For >= Django 1.10
{'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True},
]
)


Expand Down
3 changes: 2 additions & 1 deletion 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


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


Expand Down