mirror of
https://github.com/django-components/django-components.git
synced 2025-08-10 17:28:00 +00:00
chore: use src layout
This commit is contained in:
parent
f2c925e1e2
commit
a7901c7c17
20 changed files with 4 additions and 2 deletions
40
src/django_components/app_settings.py
Normal file
40
src/django_components/app_settings.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from enum import Enum
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class ContextBehavior(Enum):
|
||||
GLOBAL = "global"
|
||||
ISOLATED = "isolated"
|
||||
|
||||
|
||||
class AppSettings:
|
||||
def __init__(self):
|
||||
self.settings = getattr(settings, "COMPONENTS", {})
|
||||
|
||||
@property
|
||||
def AUTODISCOVER(self):
|
||||
return self.settings.setdefault("autodiscover", True)
|
||||
|
||||
@property
|
||||
def LIBRARIES(self):
|
||||
return self.settings.setdefault("libraries", [])
|
||||
|
||||
@property
|
||||
def TEMPLATE_CACHE_SIZE(self):
|
||||
return self.settings.setdefault("template_cache_size", 128)
|
||||
|
||||
@property
|
||||
def CONTEXT_BEHAVIOR(self):
|
||||
raw_value = self.settings.setdefault("context_behavior", ContextBehavior.GLOBAL.value)
|
||||
return self._validate_context_behavior(raw_value)
|
||||
|
||||
def _validate_context_behavior(self, raw_value):
|
||||
try:
|
||||
return ContextBehavior(raw_value)
|
||||
except ValueError:
|
||||
valid_values = [behavior.value for behavior in ContextBehavior]
|
||||
raise ValueError(f"Invalid context behavior: {raw_value}. Valid options are {valid_values}")
|
||||
|
||||
|
||||
app_settings = AppSettings()
|
Loading…
Add table
Add a link
Reference in a new issue