mark active menu item as active

This commit is contained in:
Jan Dittberner 2015-02-01 14:58:32 +01:00
parent 210d1e122c
commit 81b9bc163b
3 changed files with 31 additions and 3 deletions

View File

@ -1,6 +1,8 @@
Changelog
=========
* :support:`-` mark active menu item as active via context_processor and
corresponding template markup
* :feature:`-` add links to webmail, phpmyadmin and phppgadmin
* :release:`0.10.0 <2015-02-01>`

View File

@ -4,8 +4,13 @@ This module provides context processor implementations for gnuviechadmin.
"""
from __future__ import absolute_import, unicode_literals
import logging
from django.conf import settings
_LOGGER = logging.getLogger(__name__)
def navigation(request):
"""
@ -24,4 +29,25 @@ def navigation(request):
'phppgadmin_url': settings.GVA_LINK_PHPPGADMIN,
'active_item': 'dashboard',
}
if request.resolver_match:
viewfunc = request.resolver_match.func
viewmodule = viewfunc.__module__
if viewmodule == 'contact.views':
context['active_item'] = 'contact'
elif viewmodule == 'about.views':
context['active_item'] = 'about'
elif viewmodule in (
'hostingpackages.views', 'osusers.views', 'userdbs.views',
'managemails.views', 'websites.views', 'domains.views',
):
context['active_item'] = 'hostingpackage'
elif viewmodule in (
'allauth.account.views', 'allauth.socialaccount.views'
):
context['active_item'] = 'account'
else:
_LOGGER.debug(
'no special handling for view %s in module %s, fallback to '
'default active menu item %s',
viewfunc.__name__, viewmodule, context['active_item'])
return context

View File

@ -57,12 +57,12 @@
<li><a href="{{ phppgadmin_url }}" title="{% trans "phpPgAdmin - PostgreSQL database administration frontend" %}"><i class="icon-postgres"></i> {% trans "phpPgAdmin" %}</a></li>
</ul>
</li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li{% if active_item == 'about' %} class="active"{% endif %}><a href="#about">About</a></li>
<li{% if active_item == 'contact' %} class="active"{% endif %}><a href="#contact">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li class="dropdown">
<li class="dropdown{% if active_item == 'account' %} active{% endif %}">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{% trans "My Account" %} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
{% if user.is_staff %}<li><a href="{% url 'admin:index' %}">{% trans "Admin site" %}</a></li>{% endif %}