From 821e9010c2a5ba0a4be6590be4db730ee1fd0d69 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 13 Dec 2024 17:01:43 -0500 Subject: [PATCH 1/4] Use same guard for "last" project as project-level urls.py #11660 This check sniffs for whether this urls.py is the one being run as a project (not included by any further apps). For core arches, this would only be true if running core arches without a project. This was failing on a Django exception inside i18n_patterns(). This check is the same check that we're using in project-level settings.py --- arches/urls.py | 2 +- releases/7.6.4.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arches/urls.py b/arches/urls.py index e4ba6cf8c40..6423f379ed9 100644 --- a/arches/urls.py +++ b/arches/urls.py @@ -736,7 +736,7 @@ # This must be included in core to keep webpack happy, but cannot be appended when running a project. # See https://github.com/archesproject/arches/pull/10754 -if settings.APP_NAME == "Arches": +if settings.ROOT_URLCONF == __name__: if settings.SHOW_LANGUAGE_SWITCH is True: urlpatterns = i18n_patterns(*urlpatterns) diff --git a/releases/7.6.4.md b/releases/7.6.4.md index aa8d0877369..bdd0f85dcb5 100644 --- a/releases/7.6.4.md +++ b/releases/7.6.4.md @@ -9,6 +9,7 @@ - Cache resource relationship preflabels to improve report load time #[11583](https://github.com/archesproject/arches/issues/11583) - Fix regression where Arches is no longer overriding Django admin templates #[11668](https://github.com/archesproject/arches/issues/11668) - Fix bug causing the Edit button to not display in the map popup #[11679](https://github.com/archesproject/arches/issues/11679) +- Fix enabling multiple languages if the `APP_NAME` system settings tile had never been updated #[11660](https://github.com/archesproject/arches/issues/11660) ### Dependency changes: From fbc966a266d987af497639ccbd8f2d00dd9b9a05 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 13 Dec 2024 17:02:16 -0500 Subject: [PATCH 2/4] Update system settings from db in development also #11660 --- arches/app/models/system_settings.py | 39 +++++++++++++--------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/arches/app/models/system_settings.py b/arches/app/models/system_settings.py index 3554f88fbac..c1b8bc219b3 100644 --- a/arches/app/models/system_settings.py +++ b/arches/app/models/system_settings.py @@ -22,6 +22,9 @@ from arches.app.models import models +tiles_loaded = False + + class SystemSettings(LazySettings): """ This class can be used just like you would use settings.py @@ -33,16 +36,13 @@ class SystemSettings(LazySettings): settings.SEARCH_ITEMS_PER_PAGE # will list all settings - print settings + print(settings) """ SYSTEM_SETTINGS_RESOURCE_MODEL_ID = "ff623370-fa12-11e6-b98b-6c4008b05c4c" RESOURCE_INSTANCE_ID = "a106c400-260c-11e7-a604-14109fd34195" - def __init__(self, *args, **kwargs): - super(SystemSettings, self).__init__(*args, **kwargs) - def __str__(self): ret = [] for setting in dir(self): @@ -53,24 +53,21 @@ def __str__(self): def __getattr__(self, name): """ - By default get settings from this class which is initially populated from the settings.py filter - If a setting is requested that isn't found, assume it's saved in the database and try and retrieve it from there - by calling update_from_db first which populates this class with any settings from the database - - What this means is that update_from_db will only be called once a setting is requested that isn't initially in the settings.py file - Only then will settings from the database be applied (and potentially overwrite settings found in settings.py) - + Defer loading of system settings tiles until first access. + An effort toward avoiding module-level queries, which are discouraged: + https://docs.djangoproject.com/stable/ref/applications/#troubleshooting """ - - try: - return super(SystemSettings, self).__getattr__(name) - except ImproperlyConfigured: - raise - except: - self.update_from_db() - return super(SystemSettings, self).__getattr__( - name - ) # getattr(self, name, True) + global tiles_loaded + if not tiles_loaded: + # Optimistically set this True to avoid concurrent queries. + tiles_loaded = True + try: + self.update_from_db() + except ImportError: + # Circular imports. Try again later. + tiles_loaded = False + + return super().__getattr__(name) def setting_exists(self, name): """ From cbd60c147efdc438fb20efbb2efa8f9aa190f13b Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 13 Dec 2024 19:43:22 -0500 Subject: [PATCH 3/4] Revert "Update system settings from db in development also #11660" This reverts commit fbc966a266d987af497639ccbd8f2d00dd9b9a05. --- arches/app/models/system_settings.py | 39 +++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/arches/app/models/system_settings.py b/arches/app/models/system_settings.py index c1b8bc219b3..3554f88fbac 100644 --- a/arches/app/models/system_settings.py +++ b/arches/app/models/system_settings.py @@ -22,9 +22,6 @@ from arches.app.models import models -tiles_loaded = False - - class SystemSettings(LazySettings): """ This class can be used just like you would use settings.py @@ -36,13 +33,16 @@ class SystemSettings(LazySettings): settings.SEARCH_ITEMS_PER_PAGE # will list all settings - print(settings) + print settings """ SYSTEM_SETTINGS_RESOURCE_MODEL_ID = "ff623370-fa12-11e6-b98b-6c4008b05c4c" RESOURCE_INSTANCE_ID = "a106c400-260c-11e7-a604-14109fd34195" + def __init__(self, *args, **kwargs): + super(SystemSettings, self).__init__(*args, **kwargs) + def __str__(self): ret = [] for setting in dir(self): @@ -53,21 +53,24 @@ def __str__(self): def __getattr__(self, name): """ - Defer loading of system settings tiles until first access. - An effort toward avoiding module-level queries, which are discouraged: - https://docs.djangoproject.com/stable/ref/applications/#troubleshooting + By default get settings from this class which is initially populated from the settings.py filter + If a setting is requested that isn't found, assume it's saved in the database and try and retrieve it from there + by calling update_from_db first which populates this class with any settings from the database + + What this means is that update_from_db will only be called once a setting is requested that isn't initially in the settings.py file + Only then will settings from the database be applied (and potentially overwrite settings found in settings.py) + """ - global tiles_loaded - if not tiles_loaded: - # Optimistically set this True to avoid concurrent queries. - tiles_loaded = True - try: - self.update_from_db() - except ImportError: - # Circular imports. Try again later. - tiles_loaded = False - - return super().__getattr__(name) + + try: + return super(SystemSettings, self).__getattr__(name) + except ImproperlyConfigured: + raise + except: + self.update_from_db() + return super(SystemSettings, self).__getattr__( + name + ) # getattr(self, name, True) def setting_exists(self, name): """ From feea8897a8af4aa1cca6da51ed5ae47e1f495df7 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Thu, 19 Dec 2024 08:52:19 -0800 Subject: [PATCH 4/4] Use better heuristic for running core arches directly re #11660 --- arches/settings_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arches/settings_utils.py b/arches/settings_utils.py index b3df5b45d6e..d75587b9a22 100644 --- a/arches/settings_utils.py +++ b/arches/settings_utils.py @@ -164,7 +164,10 @@ def generate_frontend_configuration(): "WEBPACK_DEVELOPMENT_SERVER_PORT": settings.WEBPACK_DEVELOPMENT_SERVER_PORT, } - if settings.APP_NAME == "Arches": + if str(Path(app_root_path).parent) == root_dir_path: + # Running core arches directly without a project, e.g.: + # app_root_path: arches/app + # root_dir_path: arches base_path = root_dir_path else: base_path = app_root_path