Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bootstrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
__version__ = "5.3.2"

default_app_config = 'bootstrap.apps.BootstrapConfig'
16 changes: 14 additions & 2 deletions bootstrap/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from django.apps import AppConfig


class BootstrapConfig(AppConfig):
name = 'bootstrap'

def get_bootstrap_widget(self):
from bootstrap.widgets import BootstrapWidget
return BootstrapWidget
return BootstrapWidget

def get_bootstrap_field_templates(self, field, field_class, widget_class):
return [
'bootstrap/%s_%s.html' % (field.form.__class__.__name__.lower(), field.name),
'bootstrap/%s_%s.html' % (field_class, widget_class),
'bootstrap/%s.html' % field_class,
'bootstrap/field.html',
]

def modify_bootstrap_field_classes(self, classes, field):
return classes
20 changes: 11 additions & 9 deletions bootstrap/templatetags/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import forms, template
from django.apps import apps
from django.conf import settings
from django.core.paginator import Paginator
from django.template import loader
Expand All @@ -13,6 +14,8 @@

register = template.Library()

bootstrap_app_config = apps.get_app_config("bootstrap")

# https://fortawesome.github.io/Font-Awesome/icons/#file-type
FONT_AWESOME_FILE_TYPE_ICON_MAP = {
'doc': 'fa-file-word-o',
Expand All @@ -34,15 +37,15 @@ def bootstrap_icon(icon: str, **kwargs):
"""
Adds a bootstrap icon to the document. See https://icons.getbootstrap.com/ for more information.
Use kwargs to set the attributes of svg tag.

:param icon: The name of the bootstrap icon you want. for example '0-circle'.
:param class: Use to add additional classes to the icon. Defaults to 'bi'.
:param height: The height attribute of the icon. Defaults to '1em'.
:param width: The width attribute of the icon. Defaults to '1em'.
:param fill: The fill attribute of the icon. Defaults to 'currentColor'.
"""
location= f'bootstrap/bootstrap-icons/bootstrap-icons.svg#{icon}'

return {'location': location,
'attributes': {
'class': 'bi',
Expand Down Expand Up @@ -105,18 +108,17 @@ def bootstrap_field(field, classes='', template=None, **kwargs):
return ''
field_class = field.field.__class__.__name__.lower()
widget_class = field.field.widget.__class__.__name__.lower()
templates = [
'bootstrap/%s_%s.html' % (field.form.__class__.__name__.lower(), field.name),
'bootstrap/%s_%s.html' % (field_class, widget_class),
'bootstrap/%s.html' % field_class,
'bootstrap/field.html',
]
templates = bootstrap_app_config.get_bootstrap_field_templates(
field=field,
field_class=field_class,
widget_class=widget_class,
)
if template:
templates.insert(0, template)
extra_classes = getattr(field.field, 'css_classes', [])
if extra_classes:
classes += ' ' + ' '.join(extra_classes)

classes = bootstrap_app_config.modify_bootstrap_field_classes(classes=classes, field=field)
use_fieldset = getattr(field.field.widget, 'use_fieldset', False)
describedby = set(field.field.widget.attrs.get('aria-describedby', '').split())
labelledby = set(field.field.widget.attrs.get('aria-labelledby', '').split())
Expand Down