Enable breadcrumb support, use it on the login view

pull/1/head
Danielle McLean 5 years ago
parent c210650ca7
commit 84a34c89e7
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
  1. 3
      home/views.py
  2. 3
      lemonauth/views.py
  3. 15
      lemoncurry/breadcrumbs.py
  4. 13
      lemoncurry/static/lemoncurry/css/layout.styl
  5. 3
      lemoncurry/templates/lemoncurry/layout.html
  6. 14
      lemoncurry/templates/lemoncurry/tags/breadcrumbs.html
  7. 9
      lemoncurry/templatetags/lemoncurry_tags.py

@ -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',

@ -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>

@ -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…
Cancel
Save