2015-02-01 13:16:45 +01:00
|
|
|
"""
|
|
|
|
This module provides context processor implementations for gnuviechadmin.
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
from __future__ import absolute_import
|
2015-02-01 13:16:45 +01:00
|
|
|
|
2015-02-01 14:58:32 +01:00
|
|
|
import logging
|
|
|
|
|
2015-02-01 13:16:45 +01:00
|
|
|
from django.conf import settings
|
|
|
|
|
2015-02-01 22:15:40 +01:00
|
|
|
from gnuviechadmin import __version__ as gvaversion
|
|
|
|
|
2015-02-01 14:58:32 +01:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2015-02-01 13:16:45 +01:00
|
|
|
def navigation(request):
|
|
|
|
"""
|
|
|
|
Add navigation items to the request context.
|
|
|
|
|
|
|
|
:param request: Django :py:class:`HttpRequest <django.http.HttpRequest>`
|
|
|
|
:return: new context items
|
|
|
|
:rtype: dict
|
|
|
|
|
|
|
|
"""
|
2023-02-18 22:46:48 +01:00
|
|
|
if request.headers.get("x-requested-with") == "XMLHttpRequest":
|
2015-02-01 13:16:45 +01:00
|
|
|
return {}
|
|
|
|
context = {
|
2023-02-18 22:46:48 +01:00
|
|
|
"webmail_url": settings.GVA_LINK_WEBMAIL,
|
|
|
|
"phpmyadmin_url": settings.GVA_LINK_PHPMYADMIN,
|
|
|
|
"phppgadmin_url": settings.GVA_LINK_PHPPGADMIN,
|
|
|
|
"active_item": "dashboard",
|
2015-02-01 13:16:45 +01:00
|
|
|
}
|
2015-02-01 14:58:32 +01:00
|
|
|
if request.resolver_match:
|
|
|
|
viewfunc = request.resolver_match.func
|
|
|
|
viewmodule = viewfunc.__module__
|
2023-02-18 22:46:48 +01:00
|
|
|
if viewmodule == "contact_form.views":
|
|
|
|
context["active_item"] = "contact"
|
2015-02-01 14:58:32 +01:00
|
|
|
elif viewmodule in (
|
2023-02-18 22:46:48 +01:00
|
|
|
"hostingpackages.views",
|
|
|
|
"osusers.views",
|
|
|
|
"userdbs.views",
|
|
|
|
"managemails.views",
|
|
|
|
"websites.views",
|
|
|
|
"domains.views",
|
2015-02-01 14:58:32 +01:00
|
|
|
):
|
2023-02-18 22:46:48 +01:00
|
|
|
context["active_item"] = "hostingpackage"
|
|
|
|
elif viewmodule in ("allauth.account.views", "allauth.socialaccount.views"):
|
|
|
|
context["active_item"] = "account"
|
|
|
|
elif viewmodule == "django.contrib.flatpages.views" and request.path.endswith(
|
|
|
|
"/impressum/"
|
2015-02-01 16:34:46 +01:00
|
|
|
):
|
2023-02-18 22:46:48 +01:00
|
|
|
context["active_item"] = "imprint"
|
|
|
|
elif not viewmodule.startswith("django.contrib.admin"):
|
2015-02-01 14:58:32 +01:00
|
|
|
_LOGGER.debug(
|
2023-02-18 22:46:48 +01:00
|
|
|
"no special handling for view %s in module %s, fallback to "
|
|
|
|
"default active menu item %s",
|
|
|
|
viewfunc.__name__,
|
|
|
|
viewmodule,
|
|
|
|
context["active_item"],
|
|
|
|
)
|
2015-02-01 13:16:45 +01:00
|
|
|
return context
|
2015-02-01 22:15:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
def version_info(request):
|
|
|
|
"""
|
|
|
|
Context processor that adds the gnuviechadmin version to the request
|
|
|
|
context.
|
|
|
|
|
|
|
|
"""
|
|
|
|
context = {
|
2023-02-18 22:46:48 +01:00
|
|
|
"gnuviechadmin_version": gvaversion,
|
2015-02-01 22:15:40 +01:00
|
|
|
}
|
|
|
|
return context
|