forked from 00dani/lemoncurry
Enable breadcrumb support, use it on the login view
This commit is contained in:
parent
c210650ca7
commit
84a34c89e7
7 changed files with 57 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
|||
from django.shortcuts import get_object_or_404, render
|
||||
from users.models import User
|
||||
from lemoncurry import breadcrumbs
|
||||
|
||||
breadcrumbs.add('home:index', 'home')
|
||||
|
||||
|
||||
def index(request):
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from django.contrib.auth import views as auth_views
|
||||
from lemoncurry import breadcrumbs
|
||||
|
||||
breadcrumbs.add(route='lemonauth:login', label='login', parent='home:index')
|
||||
|
||||
login = auth_views.LoginView.as_view(
|
||||
template_name='lemonauth/login.html',
|
||||
|
|
15
lemoncurry/breadcrumbs.py
Normal file
15
lemoncurry/breadcrumbs.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
breadcrumbs = {}
|
||||
|
||||
|
||||
def add(route, label, parent=None):
|
||||
breadcrumbs[route] = {'label': label, 'route': route, 'parent': parent}
|
||||
|
||||
|
||||
def find(route):
|
||||
crumbs = []
|
||||
while route:
|
||||
crumb = breadcrumbs[route]
|
||||
crumbs.append(crumb)
|
||||
route = crumb['parent']
|
||||
crumbs.reverse()
|
||||
return crumbs
|
|
@ -20,9 +20,16 @@ body
|
|||
background-color $base00
|
||||
color $base07
|
||||
> header
|
||||
background-color $base01
|
||||
#navbar
|
||||
justify-content space-between
|
||||
> .navbar
|
||||
background-color $base01
|
||||
#navbar
|
||||
justify-content space-between
|
||||
> .breadcrumbs
|
||||
background-color $base02
|
||||
> .breadcrumb
|
||||
background-color transparent
|
||||
border-radius 0
|
||||
|
||||
|
||||
> main
|
||||
margin 2rem
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
{% nav_right request %}
|
||||
</div>
|
||||
</nav>
|
||||
{% if request.resolver_match.view_name %}
|
||||
{% nav_crumbs request.resolver_match.view_name %}
|
||||
{% endif %}
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
|
14
lemoncurry/templates/lemoncurry/tags/breadcrumbs.html
Normal file
14
lemoncurry/templates/lemoncurry/tags/breadcrumbs.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% if crumbs %}
|
||||
<nav class="breadcrumbs" aria-label="breadcrumb" role="navigation">
|
||||
<ol class="breadcrumb">
|
||||
{% for crumb in crumbs %}
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url crumb.route %}">{{ crumb.label }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="breadcrumb-item active" aria-current="page">
|
||||
{{ current.label }}
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
{% endif %}
|
|
@ -7,6 +7,8 @@ from django import template
|
|||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
||||
from .. import breadcrumbs
|
||||
|
||||
register = template.Library()
|
||||
cache = SimpleNamespace(package_json=None)
|
||||
|
||||
|
@ -50,3 +52,10 @@ def nav_right(request):
|
|||
MenuItem(label='log in', icon='fa fa-sign-in', url='lemonauth:login'),
|
||||
)
|
||||
return {'items': items}
|
||||
|
||||
|
||||
@register.inclusion_tag('lemoncurry/tags/breadcrumbs.html')
|
||||
def nav_crumbs(route):
|
||||
crumbs = breadcrumbs.find(route)
|
||||
current = crumbs.pop()
|
||||
return {'crumbs': crumbs, 'current': current}
|
||||
|
|
Loading…
Reference in a new issue