forked from 00dani/lemoncurry
Add basic navigation menus :3
This commit is contained in:
parent
ec45a4c250
commit
97eb5c52eb
3 changed files with 39 additions and 0 deletions
|
@ -23,6 +23,8 @@
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbar">
|
<div class="collapse navbar-collapse" id="navbar">
|
||||||
|
{% nav_left %}
|
||||||
|
{% nav_right request %}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
8
lemoncurry/templates/lemoncurry/tags/nav.html
Normal file
8
lemoncurry/templates/lemoncurry/tags/nav.html
Normal 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>
|
|
@ -1,14 +1,23 @@
|
||||||
import json
|
import json
|
||||||
|
from collections import namedtuple
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
cache = SimpleNamespace(package_json=None)
|
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
|
@register.simple_tag
|
||||||
def get_package_json():
|
def get_package_json():
|
||||||
if cache.package_json:
|
if cache.package_json:
|
||||||
|
@ -21,3 +30,23 @@ def get_package_json():
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def site_name():
|
def site_name():
|
||||||
return settings.LEMONCURRY_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}
|
||||||
|
|
Loading…
Reference in a new issue