Skip to content
Snippets Groups Projects
Commit 91e8a4f3 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added breadcrumb navigation to information app. Updated menu creator in main...

Added breadcrumb navigation to information app. Updated menu creator in main app to include auto rendering of information menu item
parent cc561439
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ from django.utils import translation
from django.conf import settings
from datetime import datetime
from dateutil.relativedelta import relativedelta
from django.core.urlresolvers import reverse
register = template.Library()
......@@ -32,20 +33,39 @@ def generate_main_menu(context):
for menu_child_item in menu_item["child_items"]:
# If url of this page matches request.path, add the active class
# AND flag that this dropdown menu contains the active item
active_class_attr = ' class="currentLink"' if request.path.startswith(menu_child_item["url"]) else ''
#active_class_attr = ' class="currentLink"' if request.path.startswith(menu_child_item["url"]) else ''
if request.path.startswith(menu_child_item["url"]):
child_item_is_active = True
dropdown_html += '<li><a href="%s">%s</a></li>' % (menu_child_item["url"], _(menu_child_item["label"]))
# If this dropdown meny contains the active item:
# If this dropdown menu contains the active item:
# add an active class to the dropdown item
active_class_attr = ' currentLink' if child_item_is_active else ''
# Prepending the list item
dropdown_html = """<li class="dropdown">
<a href="#" class="dropdown-toggle%s" data-toggle="dropdown" role="button" aria-expanded="false">%s <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">""" % (active_class_attr, _(menu_item["label"])) + dropdown_html
# Wrap up the HTML
# Wrap up the HTML
dropdown_html += "</ul></li>"
menu_html += dropdown_html
# If app information is installed, generate dropdown for it
information_installed = False
for app_name in settings.INSTALLED_APPS:
if app_name == "information":
information_installed = True
if information_installed:
dropdown_template = """<li class="dropdown">
<a href="#" class="dropdown-toggle%s" data-toggle="dropdown" role="button" aria-expanded="false">%s <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">%s</ul>
</li>"""
item_template = """<li><a href="%s">%s</a></li>"""
from information.models import Information, InformationLocale
top_level = Information.objects.filter(parent_information__isnull=True)
items_html = []
for info in top_level:
info_locale = InformationLocale.get_information_locale_with_fallback(info.pk)
items_html.append( item_template % (reverse('information:detail', kwargs={"information_id":info.pk}), info_locale.headline) )
menu_html += dropdown_template % (" currentLink" if request.path.startswith("/information") else "",_("Information"),"".join(items_html))
return menu_html
# Get the footer text in correct language
......
......@@ -2,6 +2,30 @@
{% load i18n staticfiles %}
{% block title%}{{information_locale.headline}}{%endblock%}
{% block content %}
<ol class="breadcrumb">
{% for crumb in breadcrumb reversed %}
{% if not crumb.active %}
<li><a href="{% url 'information:detail' crumb.id %}">{{ crumb.title }}</a></li>
{% else %}
{% if children_locales %}
<li class="dropdown">
<a class="dropdown-toggle" role="button" id="crumbDropdown" data-toggle="dropdown" aria-expanded="true">
{{ crumb.title }}
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="crumbDropdown">
{% for child in children_locales %}
<li role="presentation"><a role="menuitem" tabindex="-1" href="{% url 'information:detail' child.information.pk %}">{{ child.headline }}</a></li>
{% endfor %}
</ul>
</li>
{% else %}
<li class="active">{{ crumb.title }}</li>
{% endif %}
{% endif %}
{% endfor %}
</ol>
{% if information_locale.information.illustration %}
<div class="messages_illustration"><img src="{{settings.MEDIA_URL}}{{information_locale.information.illustration}}" class="img-responsive"/></div>
{% endif %}
......
......@@ -23,8 +23,8 @@ from information.models import InformationLocale, Information
def index(request):
# Check that root element exists
try:
root_information = Information.objects.get(parent_information=None)
return detail(request,root_information.id)
root_information = Information.objects.filter(parent_information__isnull=True)
return detail(request,root_information[0].id)
except:
# Fallback: Return an empty page
context = {}
......@@ -32,6 +32,31 @@ def index(request):
def detail(request, information_id):
information_locale = InformationLocale.get_information_locale_with_fallback(information_id)
# Is there a parent?
parent_information = information_locale.information.parent_information
# We get all the children too
children_locales = []
for child in information_locale.information.children.all():
children_locales.append(InformationLocale.get_information_locale_with_fallback(child.pk))
context = {'information_locale' : information_locale}
return render(request, 'information/detail.html', context)
\ No newline at end of file
context = {
'information_locale' : information_locale,
'parent_information' : parent_information,
'children_locales':children_locales,
'breadcrumb': get_breadcrumb(information_locale.information)
}
return render(request, 'information/detail.html', context)
def get_breadcrumb(information):
active_id= information.pk
breadcrumb = []#[]
while information != None:
information_locale = InformationLocale.get_information_locale_with_fallback(information.pk)
breadcrumb.append({
"id":information_locale.information.pk,
"title":information_locale.headline,
"active" : information.pk == active_id
})
information = information.parent_information
return breadcrumb
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment