Browse Source

main navigation header links now based on resource urls

master
Holger Frey 7 years ago
parent
commit
9ad8058597
  1. 5
      ordr2/resources/__init__.py
  2. 52
      ordr2/templates/layout.jinja2

5
ordr2/resources/__init__.py

@ -31,6 +31,9 @@ class BaseResource(object):
__name__ = None __name__ = None
__parent__ = None __parent__ = None
#: name of the main nav_section for template highlighting
nav_section = None
#: dict to match the next url path segment #: dict to match the next url path segment
nodes = {} nodes = {}
@ -66,6 +69,8 @@ class RootResource(BaseResource):
pyramid.request.Request pyramid.request.Request
''' '''
nav_section = 'root'
def __init__(self, request): def __init__(self, request):
''' Create the root resource ''' ''' Create the root resource '''
self.__name__ = None self.__name__ = None

52
ordr2/templates/layout.jinja2

@ -26,27 +26,39 @@
<a class="navbar-brand" href="{{ request.resource_url(request.root) }}">ordr</a> <a class="navbar-brand" href="{{ request.resource_url(request.root) }}">ordr</a>
</div> </div>
<!-- main section links --> {% if request.user %}
<ul class="navbar-nav mr-auto"> <!-- user is logged in -->
<li class="nav-item active"><a class="nav-link" href="http://localhost:6543/orders">Orders</a></li>
<li class="nav-item"><a class="nav-link" href="http://localhost:6543/faq">FAQs</a></li>
<li class="nav-item"><a class="nav-link" href="http://localhost:6543/admin">Admin</a></li>
</ul>
<!-- user login and setting stuff on the right --> <!-- main section links -->
<ul class="navbar-nav"> <ul class="navbar-nav mr-auto">
<li class="nav-item dropdown" id="user-options"> <li class="nav-item {{ 'active' if request.context.nav_section == 'orders' }}"><a class="nav-link" href="{{ request.resource_url(request.root, 'orders') }}">Orders</a></li>
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownUserSettings" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <li class="nav-item {{ 'active' if request.context.nav_section == 'root' and request.view_name == 'faq' }}"><a class="nav-link" href="{{ request.resource_url(request.root, 'faq') }}">FAQs</a></li>
Logged in as <span>HolgerFrey</span> <li class="nav-item {{ 'active' if request.context.nav_section == 'admin' }}"><a class="nav-link" href="{{ request.resource_url(request.root, 'admin') }}">Admin</a></li>
</a> </ul>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownUserSettings">
<li class="dropdown-item"><a href="http://localhost:6543/account/settings">Settings</a></li> <!-- user login and setting stuff on the right -->
<li class="dropdown-item"><a href="https://git.cpi.imtek.uni-freiburg.de/holgi/ordr2/issues">Submit an Issue</a></li> <ul class="navbar-nav">
<li class="dropdown-item"></li> <li class="nav-item dropdown" id="user-options">
<li class="dropdown-item"><a href="http://localhost:6543/account/logout">Logout</a></li> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownUserSettings" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
</ul> Logged in as <span>{{ request.user.username }}</span>
</li> </a>
</ul> <ul class="dropdown-menu" aria-labelledby="navbarDropdownUserSettings">
<li class="dropdown-item"><a href="{{ request.resource_url(request.root, 'account', 'settings') }}">Settings</a></li>
<li class="dropdown-item"><a href="https://git.cpi.imtek.uni-freiburg.de/holgi/ordr2/issues">Submit an Issue</a></li>
<li class="dropdown-item"></li>
<li class="dropdown-item"><a href="{{ request.resource_url(request.root, 'account', 'logout') }}">Logout</a></li>
</ul>
</li>
</ul>
{% else %}
<!-- No logged in user -->
<!-- main section links -->
<ul class="navbar-nav mr-auto">
<li class="nav-item {{ 'active' if request.context.nav_section == 'root' and request.view_name == 'faq' }}"><a class="nav-link" href="{{ request.resource_url(request.root, 'faq') }}">FAQs</a></li>
<li class="nav-item {{ 'active' if request.context.nav_section == 'account' and request.view_name == 'register'}}"><a class="nav-link" href="{{ request.resource_url(request.root, 'account', 'register') }}">Register</a></li>
</ul>
{% endif %}
</nav> </nav>
<!-- header level two --> <!-- header level two -->