userbar render function should not call context processor(s) (#12411)

Fixes #12410
main
Ihor Marhitych 2024-10-12 19:14:02 +02:00 zatwierdzone przez Matt Westcott
rodzic 47848f24ed
commit 6a8c2bcd98
6 zmienionych plików z 26 dodań i 3 usunięć

Wyświetl plik

@ -42,6 +42,7 @@ Changelog
* Fix: On "move page" bulk action, do not prefill the destination with the root page (Stefan Hammer)
* Fix: Ensure the default preferred language respects the `WAGTAILADMIN_PERMITTED_LANGUAGES` setting (Sébastien Corbin)
* Fix: Ensure there is consistent padding in homepage panels table headers (Aditya (megatrron))
* Fix: Prevent redundant calls to context processors when rendering userbar (Ihor Marhitych)
* Docs: Add missing `django.contrib.admin` to list of apps in "add to Django project" guide (Mohamed Rabiaa)
* Docs: Add tutorial on deploying on Ubuntu to third-party tutorials (Mohammad Fathi Rahman)
* Docs: Document that request_or_site is optional on BaseGenericSetting.load (Matt Westcott)

Wyświetl plik

@ -66,6 +66,7 @@ We have a new pagination interface for all listing views and most choosers, incl
* On "move page" bulk action, do not prefill the destination with the root page (Stefan Hammer)
* Ensure the default preferred language respects the `WAGTAILADMIN_PERMITTED_LANGUAGES` setting (Sébastien Corbin)
* Ensure there is consistent padding in homepage panels table headers (Aditya (megatrron))
* Prevent redundant calls to context processors when rendering userbar (Ihor Marhitych)
### Documentation

Wyświetl plik

@ -11,6 +11,7 @@ from wagtail import hooks
from wagtail.admin.userbar import AccessibilityItem
from wagtail.coreutils import get_dummy_request
from wagtail.models import PAGE_TEMPLATE_VAR, Locale, Page, Site
from wagtail.test.context_processors import get_call_count, reset_call_count
from wagtail.test.testapp.models import BusinessChild, BusinessIndex, SimplePage
from wagtail.test.utils import WagtailTestUtils
from wagtail.users.models import UserProfile
@ -444,11 +445,13 @@ class TestUserbarInPageServe(WagtailTestUtils, TestCase):
self.homepage.add_child(instance=self.page)
def test_userbar_rendered(self):
reset_call_count()
response = self.page.serve(self.request)
response.render()
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<template id="wagtail-userbar-template">')
self.assertEqual(get_call_count(), 1)
def test_userbar_anonymous_user_cannot_see(self):
self.request.user = AnonymousUser()

Wyświetl plik

@ -15,9 +15,7 @@ class BaseItem:
return {"self": self, "request": request}
def render(self, request):
return render_to_string(
self.template, self.get_context_data(request), request=request
)
return render_to_string(self.template, self.get_context_data(request))
class AdminItem(BaseItem):

Wyświetl plik

@ -7,3 +7,22 @@ def do_not_use_static_url(request):
return {
"STATIC_URL": lambda: exception(),
}
CALL_COUNT = 0
def count_calls(request):
global CALL_COUNT
CALL_COUNT += 1
return {}
def get_call_count():
global CALL_COUNT
return CALL_COUNT
def reset_call_count():
global CALL_COUNT
CALL_COUNT = 0

Wyświetl plik

@ -101,6 +101,7 @@ TEMPLATES = [
"django.template.context_processors.request",
"wagtail.test.context_processors.do_not_use_static_url",
"wagtail.contrib.settings.context_processors.settings",
"wagtail.test.context_processors.count_calls",
],
"debug": True, # required in order to catch template errors
},