From 67537732c0ccd707e9adc486479b82c20bc1a3f2 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 23 Jul 2018 12:35:46 +0200 Subject: [PATCH] Create the @feature_lock decorator --- calsocial/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/calsocial/utils.py b/calsocial/utils.py index 945ab2e..5a9679d 100644 --- a/calsocial/utils.py +++ b/calsocial/utils.py @@ -140,3 +140,25 @@ def beta(func): return func(*args, **kwargs) return decorated + + +def feature_lock(feature): # pylint: disable=missing-return-doc,missing-return-type-doc + """Decorator to lock a feature + + :param feature: the name of a feature + :type feature: str + """ + + def decorator(func): # pylint: disable=missing-docstring + @wraps(func) + def decorated(*args, **kwargs): # pylint: disable=missing-docstring + from calsocial.models import AppState + + if AppState[f'feature:{feature}'] == 'true': + return func(*args, **kwargs) + + return 'Feature locked' + + return decorated + + return decorator