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:
parent
72d9b13ddc
commit
9cc96f1435
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user