Repository: wagtail/wagtail

Issue:
 Adopt generic class based views for Home (aka dashboard)
See https://github.com/wagtail/wagtail/issues/8365

* Update the home (dashboard) view to be a classed based view using the Wagtail base template views
* `wagtail/admin/views/home.py`


Discussion:

Resolving patch:
diff --git a/wagtail/admin/urls/__init__.py b/wagtail/admin/urls/__init__.py
--- a/wagtail/admin/urls/__init__.py
+++ b/wagtail/admin/urls/__init__.py
@@ -23,7 +23,7 @@
 from wagtail.utils.urlpatterns import decorate_urlpatterns
 
 urlpatterns = [
-    path("", home.home, name="wagtailadmin_home"),
+    path("", home.HomeView.as_view(), name="wagtailadmin_home"),
     path("test404/", TemplateView.as_view(template_name="wagtailadmin/404.html")),
     path("api/", include(api_urls)),
     path("failwhale/", home.error_test, name="wagtailadmin_error_test"),
diff --git a/wagtail/admin/views/generic/__init__.py b/wagtail/admin/views/generic/__init__.py
--- a/wagtail/admin/views/generic/__init__.py
+++ b/wagtail/admin/views/generic/__init__.py
@@ -1,3 +1,4 @@
+from .base import WagtailAdminTemplateMixin  # noqa
 from .mixins import (  # noqa
     BeforeAfterHookMixin,
     HookResponseMixin,
diff --git a/wagtail/admin/views/home.py b/wagtail/admin/views/home.py
--- a/wagtail/admin/views/home.py
+++ b/wagtail/admin/views/home.py
@@ -9,12 +9,14 @@
 from django.forms import Media
 from django.http import Http404, HttpResponse
 from django.template.loader import render_to_string
-from django.template.response import TemplateResponse
+from django.utils.translation import gettext_lazy
+from django.views.generic.base import TemplateView
 
 from wagtail import hooks
 from wagtail.admin.navigation import get_site_for_user
 from wagtail.admin.site_summary import SiteSummaryPanel
 from wagtail.admin.ui.components import Component
+from wagtail.admin.views.generic import WagtailAdminTemplateMixin
 from wagtail.models import (
     Page,
     Revision,
@@ -212,40 +214,56 @@ def get_context_data(self, parent_context):
         return context
 
 
-def home(request):
-
-    panels = [
-        SiteSummaryPanel(request),
-        UpgradeNotificationPanel(),
-        WorkflowPagesToModeratePanel(),
-        PagesForModerationPanel(),
-        UserPagesInWorkflowModerationPanel(),
-        RecentEditsPanel(),
-        LockedPagesPanel(),
-    ]
-
-    for fn in hooks.get_hooks("construct_homepage_panels"):
-        fn(request, panels)
-
-    media = Media()
-
-    for panel in panels:
-        media += panel.media
-
-    site_details = get_site_for_user(request.user)
-
-    return TemplateResponse(
-        request,
-        "wagtailadmin/home.html",
-        {
-            "root_page": site_details["root_page"],
-            "root_site": site_details["root_site"],
-            "site_name": site_details["site_name"],
-            "panels": sorted(panels, key=lambda p: p.order),
-            "user": request.user,
-            "media": media,
-        },
-    )
+class HomeView(WagtailAdminTemplateMixin, TemplateView):
+
+    template_name = "wagtailadmin/home.html"
+    page_title = gettext_lazy("Dashboard")
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        panels = self.get_panels()
+        site_details = self.get_site_details()
+
+        context["media"] = self.get_media(panels)
+        context["panels"] = sorted(panels, key=lambda p: p.order)
+        context["user"] = self.request.user
+
+        return {**context, **site_details}
+
+    def get_media(self, panels=[]):
+        media = Media()
+
+        for panel in panels:
+            media += panel.media
+
+        return media
+
+    def get_panels(self):
+        request = self.request
+        panels = [
+            SiteSummaryPanel(request),
+            UpgradeNotificationPanel(),
+            WorkflowPagesToModeratePanel(),
+            PagesForModerationPanel(),
+            UserPagesInWorkflowModerationPanel(),
+            RecentEditsPanel(),
+            LockedPagesPanel(),
+        ]
+
+        for fn in hooks.get_hooks("construct_homepage_panels"):
+            fn(request, panels)
+
+        return panels
+
+    def get_site_details(self):
+        request = self.request
+        site = get_site_for_user(request.user)
+
+        return {
+            "root_page": site["root_page"],
+            "root_site": site["root_site"],
+            "site_name": site["site_name"],
+        }
 
 
 def error_test(request):


Test patch: