diff --git a/VIPSWeb/templatetags/template_helper.py b/VIPSWeb/templatetags/template_helper.py index f37cc3d7fa3e08f015ccea96e35d2b9f338ea0ac..fb9175e609dea13b9bf5335af4adce670e4efdb7 100644 --- a/VIPSWeb/templatetags/template_helper.py +++ b/VIPSWeb/templatetags/template_helper.py @@ -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 diff --git a/information/templates/information/detail.html b/information/templates/information/detail.html index b4f46c548bfded18b00967ed4110136dea45c1cb..cf990128362b3247dd5ec5d3aa6798bede7d3589 100644 --- a/information/templates/information/detail.html +++ b/information/templates/information/detail.html @@ -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 %} diff --git a/information/views.py b/information/views.py index e3eae1665d3aa701fcecf233b9d116ba60f6e6e4..abed76e286072a2f671dea9d8ede270b1a590ac2 100644 --- a/information/views.py +++ b/information/views.py @@ -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