0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Make LocaleMixin.locale and translations into cached properties

This avoids situations where the corresponding `get_*` functions cannot be evaluated during `setup()` because they depend on information received later (e.g. `parent_page` in the case of the page listing view)
This commit is contained in:
Matt Westcott 2024-01-19 16:50:47 +00:00 committed by Sage Abdullah
parent 72d9b13ddc
commit 9cc96f1435
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217

View File

@ -101,10 +101,13 @@ class BeforeAfterHookMixin(HookResponseMixin):
class LocaleMixin:
def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)
self.locale = self.get_locale()
self.translations = self.get_translations() if self.locale else []
@cached_property
def locale(self):
return self.get_locale()
@cached_property
def translations(self):
return self.get_translations() if self.locale else []
def get_locale(self):
if not getattr(self, "model", None):