File: bootstrap5.py

package info (click to toggle)
python-crispy-bootstrap5 2024.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 664 kB
  • sloc: python: 1,949; sh: 6; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 996 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from crispy_forms.bootstrap import Accordion
from crispy_forms.layout import Field


class FloatingField(Field):
    template = "bootstrap5/layout/floating_field.html"


class BS5Accordion(Accordion):
    """
    Bootstrap5 Accordion menu object. It wraps `AccordionGroup` objects in a
    container. It also allows the usage of accordion-flush, introduced in bootstrap5::

        BS5Accordion(
            AccordionGroup("group name", "form_field_1", "form_field_2"),
            AccordionGroup("another group name", "form_field"),
            flush=True,
            always_open=True
        )
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.flush = kwargs.pop("flush", False)
        self.always_open = kwargs.pop("always_open", False)

        if self.always_open:
            for accordion_group in self.fields:
                accordion_group.always_open = True


class Switch(Field):
    template = "bootstrap5/layout/switch.html"