Source code for ferrosoft.apps.ferrobase.views.index
# Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import TemplateView
from ferrosoft.apps.ferrobase.apps import AppMeta, INDEX_MENU, SettingsMenuRegistry
from ferrosoft.apps.ferrobase.middleware import TenantMiddleware
[docs]
class IndexView(TemplateView):
"""Platform landing page that redirects to per-app home views when configured."""
[docs]
def get(self, request, *args, **kwargs):
"""Forward authenticated users to ``APP_META.home_view`` when set.
The tenant query parameter is preserved across the redirect so the
target view stays scoped to the current tenant.
"""
if (
self.request.user.is_authenticated
and hasattr(request, "APP_META")
and isinstance(request.APP_META, AppMeta)
):
# User shall not see ferrobase index page when running individual apps.
home_view = request.APP_META.home_view
if home_view is not None and home_view != "ferrobase:index":
# Preserve tenant parameter
request_key = TenantMiddleware.TENANT_REQUEST_KEY
tenant_id = request.GET.get(request_key, None)
return redirect(
reverse(
home_view,
query=None if tenant_id is None else {request_key: tenant_id},
),
)
return super().get(request, *args, **kwargs)
[docs]
def get_template_names(self):
"""Pick the dashboard for signed-in users and the public splash otherwise."""
if self.request.user.is_authenticated:
return ["ferrobase/index/dashboard.html"]
else:
return ["ferrobase/index/unauthenticated.html"]
[docs]
def get_context_data(self, **kwargs):
"""Add the static index menu and the settings menu for the current user."""
return super().get_context_data(**kwargs) | {
"index_menu": INDEX_MENU,
"settings_menu": SettingsMenuRegistry.get_menu(self.request),
}