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. 24
      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

24
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>
{% if request.user %}
<!-- user is logged in -->
<!-- main section links --> <!-- main section links -->
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<li class="nav-item active"><a class="nav-link" href="http://localhost:6543/orders">Orders</a></li> <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>
<li class="nav-item"><a class="nav-link" href="http://localhost:6543/faq">FAQs</a></li> <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"><a class="nav-link" href="http://localhost:6543/admin">Admin</a></li> <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>
</ul> </ul>
<!-- user login and setting stuff on the right --> <!-- user login and setting stuff on the right -->
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item dropdown" id="user-options"> <li class="nav-item dropdown" id="user-options">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownUserSettings" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownUserSettings" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Logged in as <span>HolgerFrey</span> Logged in as <span>{{ request.user.username }}</span>
</a> </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownUserSettings"> <ul class="dropdown-menu" aria-labelledby="navbarDropdownUserSettings">
<li class="dropdown-item"><a href="http://localhost:6543/account/settings">Settings</a></li> <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"><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"></li>
<li class="dropdown-item"><a href="http://localhost:6543/account/logout">Logout</a></li> <li class="dropdown-item"><a href="{{ request.resource_url(request.root, 'account', 'logout') }}">Logout</a></li>
</ul> </ul>
</li> </li>
</ul> </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 -->