From 652bb58a0c49507788a5648b56ea8b7e93fe93da Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 17 Aug 2022 11:13:42 +0200 Subject: [PATCH] Fixed #33931 -- Optimized calling of get_app_list with AdminSites index/app_index --- django/contrib/admin/sites.py | 40 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 47a25608fe..52d19693ac 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -549,15 +549,15 @@ class AdminSite: Display the main admin index page, which lists all of the installed apps that have been registered in this site. """ - app_list = self.get_app_list(request) - - context = { - **self.each_context(request), - "title": self.index_title, - "subtitle": None, - "app_list": app_list, - **(extra_context or {}), - } + context = self.each_context(request) + context.update( + { + "title": self.index_title, + "subtitle": None, + "app_list": context["available_apps"], + **(extra_context or {}), + } + ) request.current_app = self.name @@ -566,19 +566,23 @@ class AdminSite: ) def app_index(self, request, app_label, extra_context=None): - app_list = self.get_app_list(request, app_label) + context = self.each_context(request) + app_list = [ + app for app in context["available_apps"] if app["app_label"] == app_label + ] if not app_list: raise Http404("The requested admin page does not exist.") - context = { - **self.each_context(request), - "title": _("%(app)s administration") % {"app": app_list[0]["name"]}, - "subtitle": None, - "app_list": app_list, - "app_label": app_label, - **(extra_context or {}), - } + context.update( + { + "title": _("%(app)s administration") % {"app": app_list[0]["name"]}, + "subtitle": None, + "app_list": app_list, + "app_label": app_label, + **(extra_context or {}), + } + ) request.current_app = self.name