Skip to content

constants

utilities.frontend_menu.constants ¤

Attributes¤

menu_item_divider_html = '<div class="dropdown-divider"></div>' module-attribute ¤

menu_item_html = '<a class="dropdown-item" href="{url}">{name}</a>' module-attribute ¤

menu_tab_html = '\n<li class="nav-item dropdown">\n <a class="nav-link dropdown-toggle" href="#" id="navbarInfoRed" role="button"\n data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n {tab}\n </a>\n <div class="dropdown-menu" aria-labelledby="navbarDropdown">\n {items}\n </div>\n</li>\n' module-attribute ¤

Classes¤

Entry ¤

Bases: NamedTuple

Tab ¤

Bases: NamedTuple

Functions¤

menu_struct(filename=None) cached ¤

Returns the menu structure.

As the function is cached, it will be called only once when the webapp is launched.

Parameters:

Name Type Description Default
filename str

Name of the file to load

None

Returns:

Type Description
list[Tab]

List[Tab]: A list of tabs to include.

Source code in utilities/frontend_menu/constants.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@lru_cache
def menu_struct(filename: Path | None = None) -> list[Tab]:
    """Returns the menu structure.

    As the function is cached, it will be called only once when the webapp is launched.

    Args:
        filename (str): Name of the file to load

    Returns:
        List[Tab]: A list of tabs to include.
    """
    if filename is None:
        filename = Path(__file__).parent / "menu.json"

    with filename.open("r") as f:
        struct = json.load(f)

    formatted: list[Tab] = []
    for tab, details in struct.items():
        entries: list[Entry] = []
        for entry in details.get("items", []):
            entries.append(Entry(**entry))
        formatted.append(Tab(tab, details.get("permission", ""), entries))

    return formatted