Skip to content

Commit

Permalink
Add missed css_class to layout templates (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosdmit authored Aug 10, 2024
1 parent ae77d38 commit 20ed62c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG FOR CRISPY-BOOTSTRAP3

## TBC

* Fixed ignoring of `css_class` attribute in `accordion.html`, `accordion-group.html` and `tab.html` templates.

## 2024.1

* Updated supported versions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="panel panel-default">
<div class="panel panel-default{% if div.css_class %} {{ div.css_class }}{% endif %}">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#{{ div.data_parent }}" href="#{{ div.css_id }}">{{ div.name }}</a>
Expand Down
2 changes: 1 addition & 1 deletion crispy_bootstrap3/templates/bootstrap3/accordion.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="panel-group" id="{{ accordion.css_id }}">
<div class="panel-group{% if accordion.css_class %} {{ accordion.css_class }}{% endif %}" id="{{ accordion.css_id }}">
{{ content }}
</div>
2 changes: 1 addition & 1 deletion crispy_bootstrap3/templates/bootstrap3/layout/tab.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul{% if tabs.css_id %} id="{{ tabs.css_id }}"{% endif %} class="nav nav-tabs">
<ul{% if tabs.css_id %} id="{{ tabs.css_id }}"{% endif %} class="nav nav-tabs{% if tabs.css_class %} {{ tabs.css_class }}{% endif %}">
{{ links }}
</ul>
<div class="tab-content panel-body">
Expand Down
45 changes: 44 additions & 1 deletion tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ def test_inline_radios(self):
html = render_crispy_form(test_form)
assert html.count('radio-inline"') == 2

@pytest.mark.xfail(
__version__ < "2.3",
reason="Issue #1395 - AccordionGroup gets unexpected css_class 'active'",
)
def test_accordion_and_accordiongroup(self):
test_form = SampleForm()
test_form.helper = FormHelper()
Expand All @@ -230,6 +234,44 @@ def test_accordion_and_accordiongroup(self):
assert html.count('name="password1"') == 1
assert html.count('name="password2"') == 1

def test_accordion_css_class_is_applied(self):
classes = "one two three"
test_form = SampleForm()
test_form.helper = FormHelper()
test_form.helper.form_tag = False
test_form.helper.layout = Layout(
Accordion(
AccordionGroup("one", "first_name"),
css_class=classes,
css_id="super-accordion",
)
)
html = render_crispy_form(test_form)

assert (
html.count('<div class="panel-group %s" id="super-accordion"' % classes)
== 1
)

@pytest.mark.xfail(
__version__ < "2.3",
reason="Issue #1395 - AccordionGroup gets unexpected css_class 'active'",
)
def test_accordion_group_css_class_is_applied(self):
classes = "one two three"
test_form = SampleForm()
test_form.helper = FormHelper()
test_form.helper.form_tag = False
test_form.helper.layout = Layout(
Accordion(
AccordionGroup("one", "first_name", css_class=classes),
AccordionGroup("two", "password1", "password2"),
)
)
html = render_crispy_form(test_form)

assert html.count('<div class="panel panel-default %s"' % classes) == 1

def test_accordion_active_false_not_rendered(self):
test_form = SampleForm()
test_form.helper = FormHelper()
Expand Down Expand Up @@ -288,13 +330,14 @@ def test_tab_and_tab_holder(self):
css_class="first-tab-class active",
),
Tab("two", "password1", "password2"),
css_class="custom-class",
)
)
html = render_crispy_form(test_form)

assert (
html.count(
'<ul class="nav nav-tabs"> <li class="tab-pane active">'
'<ul class="nav nav-tabs custom-class"> <li class="tab-pane active">'
'<a href="#custom-name" data-toggle="tab">One</a></li>'
)
== 1
Expand Down

0 comments on commit 20ed62c

Please sign in to comment.