Skip to content

Commit

Permalink
Update system settings from db in development also #11660
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Dec 13, 2024
1 parent a7c5c85 commit 3658a2c
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions arches/app/models/system_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
"""
Expand Down

0 comments on commit 3658a2c

Please sign in to comment.