diff --git a/uffd/navbar.py b/uffd/navbar.py index 10579e5fb9c22bc707e8a1b511e0932a072bface..dc46b76355f9d0cbfc0b3037a42a1d56b11bed81 100644 --- a/uffd/navbar.py +++ b/uffd/navbar.py @@ -3,7 +3,7 @@ navbarList = [] # pylint: enable=invalid-name def setup_navbar(app): - app.jinja_env.globals['navbar'] = navbarList + app.jinja_env.globals['getnavbar'] = lambda: [n for n in navbarList if n['visible']()] # iconlib can be 'bootstrap' # ( see: http://getbootstrap.com/components/#glyphicons ) @@ -27,7 +27,7 @@ def register_navbar(name, iconlib='fa', icon=None, group=None, endpoint=None, bl item['endpoint'] = urlendpoint item['name'] = name item['blueprint'] = blueprint - item['visible'] = visible + item['visible'] = visible or (lambda: True) navbarList.append(item) return func return wrapper diff --git a/uffd/templates/base.html b/uffd/templates/base.html index ac9e2af212b131655c802648889acd8159c44b1d..5ab3cba85decb7aaa3eabaeec0df106ee46b8ebc 100644 --- a/uffd/templates/base.html +++ b/uffd/templates/base.html @@ -36,17 +36,18 @@ <nav class="navbar navbar-expand-md navbar-dark bg-dark static-top" > <a class="navbar-brand" href="{{ url_for('index') }}">uffd</a> + {% if getnavbar() %} <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#baseNavbar" aria-controls="baseNavbar" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="baseNavbar"> <ul class="navbar-nav mr-auto"> - {% for n in navbar if (not n.group) and (not n.visible or n.visible()) %} + {% for n in getnavbar() if not n.group %} {{ navbaricon(n) }} {% endfor %} - {% for grouper, list in navbar|rejectattr("group", "none")|groupby("group") %} + {% for grouper, list in getnavbar()|rejectattr("group", "none")|groupby("group") %} <li class="nav-item dropdown {% if request.endpoint in list|map(attribute='endpoint') %} active{% endif %}"> <a class="nav-link dropdown-toggle dropdow-clickable" @@ -76,9 +77,8 @@ </li> </ul> {% endif %} - - </div> + {% endif %} </nav> {% endblock navbar %}