Skip to content

Commit

Permalink
Cleanup Django versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Apr 23, 2024
1 parent c6395a9 commit a8979e6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
12 changes: 1 addition & 11 deletions src/bootstrap3/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
render_label,
)
from .text import text_value
from .utils import IS_PRE_DJANGO4, add_css_class, render_template_file
from .utils import add_css_class, render_template_file

try:
# If Django is set up without a database, importing this widget gives RuntimeError
Expand Down Expand Up @@ -313,18 +313,8 @@ def add_widget_attrs(self):

def list_to_class(self, html, klass):
classes = add_css_class(klass, self.get_size_class())
if IS_PRE_DJANGO4:
return self._list_to_class_pre_django4(html, classes)
return re.sub("\s*<div>\s*<label", f' <div class="{classes}"><label', html)

def _list_to_class_pre_django4(self, html, classes):
return (
html.replace("<ul", "<div")
.replace("</ul>", "</div>")
.replace("<li", f'<div class="{classes}"')
.replace("</li>", "</div>")
)

def put_inside_label(self, html):
content = f"{html} {self.label}"
return render_label(
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from .text import text_value

DJANGO_VERSION = get_version()
# TODO: Remove after support for Django 3.x ends
IS_PRE_DJANGO4 = DJANGO_VERSION < "4"
IS_DJANGO5 = DJANGO_VERSION >= "5"

# RegEx for quoted string
Expand Down
6 changes: 0 additions & 6 deletions tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from bootstrap3.text import text_concat, text_value
from bootstrap3.utils import (
IS_DJANGO5,
IS_PRE_DJANGO4,
add_css_class,
render_tag,
url_to_attrs_dict,
Expand Down Expand Up @@ -572,11 +571,6 @@ def test_radioset_inline(self):
</div>
</div>
"""
if IS_PRE_DJANGO4:
expected = expected.replace(
'<label class="sr-only">Radio</label>',
'<label class="sr-only" for="id_radio_0">Radio</label>',
)
self.assertHTMLEqual(res, expected)
self.assertIn(
' <div class="radio">',
Expand Down

0 comments on commit a8979e6

Please sign in to comment.