From 84a34c89e7b79dfcca509bbc3ef7aafd10fdaa5f Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Wed, 25 Oct 2017 00:25:41 +1100 Subject: [PATCH] Enable breadcrumb support, use it on the login view --- home/views.py | 3 +++ lemonauth/views.py | 3 +++ lemoncurry/breadcrumbs.py | 15 +++++++++++++++ lemoncurry/static/lemoncurry/css/layout.styl | 13 ++++++++++--- lemoncurry/templates/lemoncurry/layout.html | 3 +++ .../templates/lemoncurry/tags/breadcrumbs.html | 14 ++++++++++++++ lemoncurry/templatetags/lemoncurry_tags.py | 9 +++++++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 lemoncurry/breadcrumbs.py create mode 100644 lemoncurry/templates/lemoncurry/tags/breadcrumbs.html diff --git a/home/views.py b/home/views.py index 9bc157c..e2060b3 100644 --- a/home/views.py +++ b/home/views.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): diff --git a/lemonauth/views.py b/lemonauth/views.py index d2cd871..fd03dac 100644 --- a/lemonauth/views.py +++ b/lemonauth/views.py @@ -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', diff --git a/lemoncurry/breadcrumbs.py b/lemoncurry/breadcrumbs.py new file mode 100644 index 0000000..d71e6ba --- /dev/null +++ b/lemoncurry/breadcrumbs.py @@ -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 diff --git a/lemoncurry/static/lemoncurry/css/layout.styl b/lemoncurry/static/lemoncurry/css/layout.styl index 7bff2c8..331a527 100644 --- a/lemoncurry/static/lemoncurry/css/layout.styl +++ b/lemoncurry/static/lemoncurry/css/layout.styl @@ -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 diff --git a/lemoncurry/templates/lemoncurry/layout.html b/lemoncurry/templates/lemoncurry/layout.html index cb7ba3d..a94cd9d 100644 --- a/lemoncurry/templates/lemoncurry/layout.html +++ b/lemoncurry/templates/lemoncurry/layout.html @@ -29,6 +29,9 @@ {% nav_right request %} + {% if request.resolver_match.view_name %} + {% nav_crumbs request.resolver_match.view_name %} + {% endif %}
diff --git a/lemoncurry/templates/lemoncurry/tags/breadcrumbs.html b/lemoncurry/templates/lemoncurry/tags/breadcrumbs.html new file mode 100644 index 0000000..607bcc1 --- /dev/null +++ b/lemoncurry/templates/lemoncurry/tags/breadcrumbs.html @@ -0,0 +1,14 @@ +{% if crumbs %} + +{% endif %} diff --git a/lemoncurry/templatetags/lemoncurry_tags.py b/lemoncurry/templatetags/lemoncurry_tags.py index 1d8b9d2..ced1b21 100644 --- a/lemoncurry/templatetags/lemoncurry_tags.py +++ b/lemoncurry/templatetags/lemoncurry_tags.py @@ -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}