예제 #1
0
파일: forms.py 프로젝트: LinuxHaus/checkmk
def header(
    title: str,
    isopen: bool = True,
    table_id: str = "",
    narrow: bool = False,
    css: Optional[str] = None,
    show_table_head: bool = True,
    show_more_toggle: bool = False,
    show_more_mode: bool = False,
    help_text: Union[str, HTML, None] = None,
) -> None:
    global g_header_open, g_section_open
    if g_header_open:
        end()

    id_ = base64.b64encode(title.encode()).decode()
    treename = html.form_name or "nform"
    isopen = user.get_tree_state(treename, id_, isopen)
    container_id = foldable_container_id(treename, id_)

    class_ = ["nform"]
    if narrow:
        class_.append("narrow")
    if css:
        class_.append(css)
    class_.append("open" if isopen else "closed")
    if user.get_show_more_setting("foldable_%s" % id_) or show_more_mode:
        class_.append("more")

    html.open_table(
        id_=table_id if table_id else None,
        class_=class_,
    )

    if show_table_head:
        _table_head(
            treename=treename,
            id_=id_,
            isopen=isopen,
            title=title,
            show_more_toggle=show_more_toggle,
            help_text=help_text,
        )

    html.open_tbody(id_=container_id, class_=["open" if isopen else "closed"])
    html.tr(HTMLWriter.render_td("", colspan=2))
    g_header_open = True
    g_section_open = False
예제 #2
0
파일: forms.py 프로젝트: bbaumer/checkmk
def header(
    title: str,
    isopen: bool = True,
    table_id: str = "",
    narrow: bool = False,
    css: Optional[str] = None,
    show_table_head: bool = True,
    show_more_toggle: bool = False,
    show_more_mode: bool = False,
    help_text: Union[str, HTML, None] = None,
) -> None:
    global g_header_open, g_section_open
    if g_header_open:
        end()

    id_ = ensure_str(base64.b64encode(ensure_binary(title)))
    treename = html.form_name or "nform"
    isopen = config.user.get_tree_state(treename, id_, isopen)
    container_id = foldable_container_id(treename, id_)

    html.open_table(id_=table_id if table_id else None,
                    class_=[
                        "nform",
                        "narrow" if narrow else None,
                        css if css else None,
                        "open" if isopen else "closed",
                        "more" if config.user.get_show_more_setting("foldable_%s" % id_) or
                        show_more_mode else None,
                    ])

    if show_table_head:
        _table_head(
            treename=treename,
            id_=id_,
            isopen=isopen,
            title=title,
            show_more_toggle=show_more_toggle,
            help_text=help_text,
        )

    html.open_tbody(id_=container_id, class_=["open" if isopen else "closed"])
    html.tr(html.render_td('', colspan=2))
    g_header_open = True
    g_section_open = False
예제 #3
0
def test_foldable_container_id() -> None:
    assert foldable_container_id("name", "id") == "tree.name.id"