Create the @beta decorator

This commit is contained in:
Gergely Polonkai 2018-07-23 12:20:39 +02:00
parent a97d884f42
commit f7d807370d

View File

@ -18,6 +18,11 @@
""" """
from contextlib import contextmanager 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 @contextmanager
def force_locale(locale): def force_locale(locale):
@ -119,3 +124,19 @@ class RoutedMixin:
return func return func
return decorator 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