Ejemplo n.º 1
0
def render_collapsible(lst,
                       item_role='collapsible-item',
                       title=None,
                       expanded=False,
                       **kwargs):
    """
    Renders a queryset or list of objects

    Args:
        lst:
            List or queryset of objects inside the collapsible list.
        item_role:
            Role assigned to each element in the list. Defaults to
            'collapsible-item'.
        title (bool):
            Title in which the list of object is displayed.
        expanded (str):
            If true, start list in the "expanded" state.
    """
    if title is None:
        if isinstance(lst, QuerySet):
            title = title.model._meta.verbose_name_plural
        else:
            raise TypeError('must provide an explicit title!')

    data = [render(x, item_role, **kwargs) for x in lst]
    random_id = str(uuid.uuid4())
    display = 'block' if expanded else 'none'

    return div(
        class_='CollapsibleList'
    )[h2(onclick=f"$('#{random_id}').toggle()",
         children=[title, span(f'({len(data)})'),
                   fa_icon('angle-down')]),
      html_list(data, style=f'display: {display}', id=random_id), ]
Ejemplo n.º 2
0
def render_collapsible(lst,
                       item_role='collapsible-item',
                       title=None,
                       expanded=False,
                       **kwargs):
    """
    Renders a queryset or list of objects

    Args:
        lst:
            List or queryset of objects inside the collapsible list.
        item_role:
            Role assigned to each element in the list. Defaults to
            'collapsible-item'.
        title (bool):
            Title in which the list of object is displayed.
        expanded (str):
            If true, start list in the "expanded" state.
    """
    if title is None:
        if isinstance(lst, QuerySet):
            title = title.model._meta.verbose_name_plural
        else:
            raise TypeError('must provide an explicit title!')

    data = [html(x, item_role, **kwargs) for x in lst]
    return div(class_='CollapsibleList', is_component=True)[
        h2([title, span(f'({len(data)})'
                        ), fa_icon('angle-up')]),
        div(class_='CollapsibleList-data')[html_list(data), ]]
Ejemplo n.º 3
0
def collapsible(data, title=None, collapsed=False):
    """
    Renders a collapsible content.
    """

    angle = fa_icon("angle-up", class_="collapsible__handle")
    return div(
        class_="collapsible",
        is_component=True,
        is_collapsed=collapsed,
        children=[
            h2([title, angle], class_="collapsible__title"),
            div(data, class_="collapsible__data"),
        ],
    )