32 lines
645 B
Python
32 lines
645 B
Python
import functools
|
|
|
|
import jingrow
|
|
|
|
SETTINGS_PAGETYPE = "Jcloude Settings"
|
|
|
|
|
|
def enabled(key: str, default_value=None, raise_error: bool = False):
|
|
"""
|
|
Decorator to check if a feature is enabled in Jcloude Settings.
|
|
|
|
Example:
|
|
```python
|
|
@settings.enabled("some_feature_key")
|
|
def some_function():
|
|
pass
|
|
```
|
|
"""
|
|
|
|
def wrapped(func):
|
|
@functools.wraps(func)
|
|
def inner(*args, **kwargs):
|
|
if jingrow.db.get_single_value(SETTINGS_PAGETYPE, key, cache=True):
|
|
return func(*args, **kwargs)
|
|
if raise_error:
|
|
jingrow.throw("This feature is disabled", jingrow.ValidationError)
|
|
return default_value
|
|
|
|
return inner
|
|
|
|
return wrapped
|