diff --git a/adit_radis_shared/common/middlewares.py b/adit_radis_shared/common/middlewares.py index 771f873..9ab99bb 100644 --- a/adit_radis_shared/common/middlewares.py +++ b/adit_radis_shared/common/middlewares.py @@ -31,7 +31,6 @@ def __call__(self, request: HtmxHttpRequest): return self.get_response(request) project_settings = ProjectSettings.get() - assert project_settings if project_settings and project_settings.maintenance and not request.user.is_staff: if request.path.startswith("/api/"): raise ServiceUnavailable diff --git a/adit_radis_shared/common/models.py b/adit_radis_shared/common/models.py index ed7671a..f2cf5ba 100644 --- a/adit_radis_shared/common/models.py +++ b/adit_radis_shared/common/models.py @@ -13,8 +13,12 @@ def __str__(self) -> str: return f"{self.__class__.__name__} [ID {self.id}]" @classmethod - def get(cls): - return cls.objects.first() + def get(cls) -> "ProjectSettings": + project_settings = cls.objects.first() + # We made sure during startup that there is always a ProjectSettings + # (see common/apps.py) + assert project_settings + return project_settings class AppSettings(models.Model): @@ -25,5 +29,9 @@ class Meta: abstract = True @classmethod - def get(cls): - return cls.objects.first() + def get(cls) -> "AppSettings": + app_settings = cls.objects.first() + # We made sure during startup that there is always a AppSettings + # (see apps.py of the specific app) + assert app_settings + return app_settings diff --git a/adit_radis_shared/common/views.py b/adit_radis_shared/common/views.py index f577b70..0735af2 100644 --- a/adit_radis_shared/common/views.py +++ b/adit_radis_shared/common/views.py @@ -33,7 +33,7 @@ class BaseHomeView(TemplateView): def get_context_data(self, **kwargs) -> dict[str, Any]: context = super().get_context_data(**kwargs) project_settings = ProjectSettings.get() - context["announcement"] = project_settings.announcement if project_settings else "" + context["announcement"] = project_settings.announcement return context diff --git a/example_project/example_project/example_app/urls.py b/example_project/example_project/example_app/urls.py index 4560044..705a6b8 100644 --- a/example_project/example_project/example_app/urls.py +++ b/example_project/example_project/example_app/urls.py @@ -3,14 +3,14 @@ from .views import ( AsyncExampleClassView, ExampleListView, + HomeView, admin_section, example_messages, example_toasts, - home, ) urlpatterns = [ - path("", home, name="home"), + path("", HomeView.as_view(), name="home"), path("admin-section/", admin_section, name="admin_section"), path( "examples/", diff --git a/example_project/example_project/example_app/views.py b/example_project/example_project/example_app/views.py index 92251d4..6a8bec8 100644 --- a/example_project/example_project/example_app/views.py +++ b/example_project/example_project/example_app/views.py @@ -10,10 +10,11 @@ from django.views.generic import TemplateView from adit_radis_shared.accounts.models import User +from adit_radis_shared.common.views import BaseHomeView -def home(request: HttpRequest) -> HttpResponse: - return render(request, "example_app/home.html", {}) +class HomeView(BaseHomeView): + template_name = "example_app/home.html" @login_required