Source code for abed.html.common

# -*- coding: utf-8 -*-

"""
Common HTML shared between all pages (the navbar for instance)

"""

import dominate

tags = dominate.tags

from .utils import AbedHTMLTypes
from ..utils import clean_str








[docs]def generate_buttons(tables, attribute): values = sorted(set([getattr(t, attribute) for t in tables])) buttons = [] for value in values: clean = clean_str(value) btn = { "_id": "%s_%s" % (attribute, clean), "name": attribute, "value": clean, "label": value, "active": False, } buttons.append(btn) if buttons: buttons[0]["active"] = True return buttons
[docs]def bootstrap_radio_btn(_id, name, value, label, active=False): cls = "btn btn-primary active" if active else "btn btn-primary" btn = tags.label(_class=cls) if active: btn += tags.input( type="radio", id=_id, name=name, value=value, checked=True ) else: btn += tags.input(type="radio", id=_id, name=name, value=value) btn += dominate.util.text(label) return btn
[docs]def bootstrap_radio_group(btndefs): with tags.div(_class="btn-group", data_toggle="buttons") as bgrp: for btndef in btndefs: bootstrap_radio_btn(**btndef) return bgrp