Add basic navigation menus :3

This commit is contained in:
Danielle McLean 2017-10-24 15:01:17 +11:00
parent ec45a4c250
commit 97eb5c52eb
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
3 changed files with 39 additions and 0 deletions

View file

@ -23,6 +23,8 @@
</button>
<div class="collapse navbar-collapse" id="navbar">
{% nav_left %}
{% nav_right request %}
</div>
</nav>
</header>

View file

@ -0,0 +1,8 @@
<ul class="navbar-nav">
{% for item in items %}
<li class="nav-item"><a class="nav-link" href="{{ item.url }}">
<i class="{{ item.icon }}"></i>
{{ item.label }}
</a></li>
{% endfor %}
</ul>

View file

@ -1,14 +1,23 @@
import json
from collections import namedtuple
from os.path import join
from types import SimpleNamespace
from django import template
from django.conf import settings
from django.urls import reverse
register = template.Library()
cache = SimpleNamespace(package_json=None)
class MenuItem:
def __init__(self, label, icon, url):
self.label = label
self.icon = icon
self.url = reverse(url)
@register.simple_tag
def get_package_json():
if cache.package_json:
@ -21,3 +30,23 @@ def get_package_json():
@register.simple_tag
def site_name():
return settings.LEMONCURRY_SITE_NAME
@register.inclusion_tag('lemoncurry/tags/nav.html')
def nav_left():
items = ()
return {'items': items}
@register.inclusion_tag('lemoncurry/tags/nav.html')
def nav_right(request):
if request.user.is_authenticated():
items = (
MenuItem(label='admin', icon='fa fa-gear', url='admin:index'),
MenuItem(label='log out', icon='fa fa-sign-out', url='admin:logout'),
)
else:
items = (
MenuItem(label='log in', icon='fa fa-sign-in', url='admin:login'),
)
return {'items': items}