Browse Source

adjusted templates to acl setup

php2python
Holger Frey 7 years ago
parent
commit
779be58392
  1. 3
      ordr2/resources/__init__.py
  2. 17
      ordr2/templates/layout.jinja2
  3. 1
      ordr2/views/pages.py

3
ordr2/resources/__init__.py

@ -6,6 +6,8 @@ class Root(object): @@ -6,6 +6,8 @@ class Root(object):
__name__ = None
__parent__ = None
nav_highlight = None
def __init__(self, request):
self._request = request
@ -13,6 +15,7 @@ class Root(object): @@ -13,6 +15,7 @@ class Root(object):
return [ (Allow, Everyone, 'view') ]
def includeme(config):
'''
Initialize the resources for traversal in a Pyramid app.

17
ordr2/templates/layout.jinja2

@ -24,13 +24,12 @@ @@ -24,13 +24,12 @@
<div class="navbar-inner">
<div class="container-fluid">
<a href="{{request.resource_url(request.root)}}" class="brand">ordr</a>
{# TODO:
{% if request.user %}
<ul class="nav">
<li {% if is_active %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'orders')}}">Orders</a></li>
<li {% if is_active %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'faq')}}">FAQs</a></li>
{% if request.user.role == 'admin' %}
<li {% if is_active %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'admin')}}">Admin</a></li>
<li {% if context.nav_highlight == 'orders' %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'orders')}}">Orders</a></li>
<li {% if context.nav_highlight == 'faq' %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'faq')}}">FAQs</a></li>
{% if request.user.role.name == 'ADMIN' %}
<li {% if context.nav_highlight == 'admin' %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'admin')}}">Admin</a></li>
{% endif %}
</ul>
<ul class="nav pull-right">
@ -47,17 +46,17 @@ @@ -47,17 +46,17 @@
</ul>
{% else %}
<ul class="nav">
<li {% if is_active %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'register')}}">Register</a></li>
<li {% if is_active %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'about')}}">About</a></li>
<li {% if context.nav_highlight == 'register' %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'register')}}">Register</a></li>
<li {% if not context.nav_highlight %} class="active" {% endif %}><a href="{{request.resource_url(request.root, 'about')}}">About</a></li>
</ul>
<form action="{{request.resource_url(request.root, 'account', 'login')}}" method="post">
<form action="{{request.resource_url(request.root, 'account', 'login')}}" method="post" class="navbar-form pull-right">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
<input type="hidden" name="redirect" value="{{request.url}}" />
<input name="username" type="text" placeholder="Username" class="input-small">
<input name="password" type="password" placeholder="Password" class="input-small">
<button type="submit" class="btn">Log in</button>
</form>
{% endif %}
#}
</div>
</div>
</header>

1
ordr2/views/pages.py

@ -18,4 +18,5 @@ def welcome(context, request): @@ -18,4 +18,5 @@ def welcome(context, request):
renderer='../templates/pages/faq.jinja2'
)
def faqs(context, request):
context.nav_highlight = 'faq'
return {}