mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
app: Allow apps to instantiate without Django initialization
- When tags are added to Menu and Shortcut components, we will need to access info.tags which tries to extract the original string from lazy proxy. This requires Django initialized. When privileged process tries to initialize the app without initializing Django, this leads to an error. Fix this by extracing the original string from a lazy proxy a hacky way. Tests: - Running diagnostics does not show errors with Django initialization in checks for configuration links. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
parent
67cef398e1
commit
196a2deb6f
@ -532,9 +532,19 @@ class Info(FollowerComponent):
|
||||
These can only be retrieved after Django has been configured.
|
||||
"""
|
||||
# Store untranslated original strings instead of proxy objects
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils.functional import Promise
|
||||
from django.utils.translation import override
|
||||
with override(language=None):
|
||||
return [str(tag) for tag in self._tags]
|
||||
try:
|
||||
with override(language=None):
|
||||
return [str(tag) for tag in self._tags]
|
||||
except ImproperlyConfigured:
|
||||
# Hack to allow apps to be instantiated without Django
|
||||
# initialization as required by privileged process.
|
||||
return [
|
||||
tag._proxy____args[0] if isinstance(tag, Promise) else tag
|
||||
for tag in self._tags
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def list_tags(self) -> list[str]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user