Skip to content

jokiefer/django-bootstrap-swt

Repository files navigation

django-bootstrap-swt - An app for creating bootstrap components on python level

Quality Gate Status Coverage Documentation Status PyPI version

django-bootstrap-swt simplifies the task of building HTML pages with bootstrap components by using the java swt concept. This reduces your html code duplication, cause you can use predefined bootstrap components.

Features:

  • Create any bootstrap component on backend level.
  • Creates uniq id's for bootstrap components like accordion and modal to avoid id conflicts in javascript.
  • supports async data fetching for modal and accordion components.

Example

Start by adding django_bootstrap_swt to your INSTALLED_APPS setting like this:

INSTALLED_APPS = (
    ...,
    "django_bootstrap_swt",
)

Creating a bootstrap component is as simple as:

item_list = [ListGroupItem(left='text-at-the-left', center='text-at-the-center', right='text-at-the-right')

list_group = ListGroup(items=item_list)

my_modal = Modal(title=f'Details of {self.object.title}',
                 modal_body=list_group,
                 btn_value='Open modal',
                 btn_color=ButtonColorEnum.SECONDARY,
                 btn_tooltip='Click this button to open modal',
                 size=ModalSizeEnum.LARGE,)

All django-bootstrap-swt components returns the rendered template as string. So you can simply concatenate the components:

accordion_title = python_object.str_attribute + Badge(value='123')

If you need a SafeString instead of string you can call the render() function manually:

safe_string = Badge(value='123').render(safe=True)

Check out the documentation for more details.