mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
Change context behavior setting to enum
This commit is contained in:
parent
8971849922
commit
560b721523
5 changed files with 48 additions and 9 deletions
|
@ -1,6 +1,13 @@
|
|||
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", {})
|
||||
|
@ -18,8 +25,20 @@ class AppSettings:
|
|||
return self.settings.setdefault("template_cache_size", 128)
|
||||
|
||||
@property
|
||||
def ISOLATE_COMPONENT_CONTEXT(self):
|
||||
return self.settings.setdefault("isolate_component_context", False)
|
||||
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