0
0
mirror of https://github.com/django/django.git synced 2024-11-21 19:09:18 +01:00

Fixed #33931 -- Optimized calling of get_app_list with AdminSites index/app_index

This commit is contained in:
Daniel Hahler 2022-08-17 11:13:42 +02:00
parent e9fd2b5724
commit 652bb58a0c

View File

@ -549,15 +549,15 @@ class AdminSite:
Display the main admin index page, which lists all of the installed Display the main admin index page, which lists all of the installed
apps that have been registered in this site. apps that have been registered in this site.
""" """
app_list = self.get_app_list(request) context = self.each_context(request)
context.update(
context = { {
**self.each_context(request), "title": self.index_title,
"title": self.index_title, "subtitle": None,
"subtitle": None, "app_list": context["available_apps"],
"app_list": app_list, **(extra_context or {}),
**(extra_context or {}), }
} )
request.current_app = self.name request.current_app = self.name
@ -566,19 +566,23 @@ class AdminSite:
) )
def app_index(self, request, app_label, extra_context=None): 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: if not app_list:
raise Http404("The requested admin page does not exist.") raise Http404("The requested admin page does not exist.")
context = { context.update(
**self.each_context(request), {
"title": _("%(app)s administration") % {"app": app_list[0]["name"]}, "title": _("%(app)s administration") % {"app": app_list[0]["name"]},
"subtitle": None, "subtitle": None,
"app_list": app_list, "app_list": app_list,
"app_label": app_label, "app_label": app_label,
**(extra_context or {}), **(extra_context or {}),
} }
)
request.current_app = self.name request.current_app = self.name