-
Tor-Einar Skog authored
Changed breadcrumb navigation
Tor-Einar Skog authoredChanged breadcrumb navigation
views.py 2.70 KiB
#
# Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
#
# This file is part of VIPSWeb.
# VIPSWeb is free software: you can redistribute it and/or modify
# it under the terms of the NIBIO Open Source License as published by
# NIBIO, either version 1 of the License, or (at your option) any
# later version.
#
# VIPSWeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# NIBIO Open Source License for more details.
#
# You should have received a copy of the NIBIO Open Source License
# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>.
#
from django.shortcuts import render
from information.models import InformationLocale, Information
def index(request):
# Check that root element exists
try:
root_information = Information.objects.filter(parent_information__isnull=True)
return detail(request,root_information[0].id)
except:
# Fallback: Return an empty page
context = {}
return render(request, 'information/index.html', context)
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,
#'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)
children_locales = []
for child in information_locale.information.children.all():
children_locales.append(InformationLocale.get_information_locale_with_fallback(child.pk))
breadcrumb.append({
"id":information_locale.information.pk,
"title":information_locale.headline,
"active" : information.pk == active_id,
"children_locales" : children_locales
})
information = information.parent_information
return breadcrumb