From f7d807370d6a517ebce6e098588dd78d4ee2a921 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 23 Jul 2018 12:20:39 +0200 Subject: [PATCH] Create the @beta decorator --- calsocial/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/calsocial/utils.py b/calsocial/utils.py index 036657e..945ab2e 100644 --- a/calsocial/utils.py +++ b/calsocial/utils.py @@ -18,6 +18,11 @@ """ from contextlib import contextmanager +from functools import wraps + +from flask import flash, redirect, url_for +from flask_babelex import gettext as _ +from flask_security import current_user @contextmanager def force_locale(locale): @@ -119,3 +124,19 @@ class RoutedMixin: return func return decorator + + +def beta(func): + """Decorator to hide beta features from non-beta testers + """ + + @wraps(func) + def decorated(*args, **kwargs): # pylint: disable=missing-docstring + if current_user.settings['beta'] != 'True': + flash(_('Join the beta testers to enable this functionality!')) + + return redirect(url_for('account.settings')) + + return func(*args, **kwargs) + + return decorated