Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather.

def is_active_feature(feature, redirect_to=None, redirect=None):
  """
  Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather.
  """
  def _is_active_feature(func):
    @wraps(func)
    def wrapped(*args, **kwargs):

      if not is_active(feature):
        url = redirect_to
        if redirect:
          url = url_for(redirect)

        if url:
          log.debug(u'Feature {feature} is off, redirecting to {url}'.format(feature=feature, url=url))
          return _redirect(url, code=302)
        else:
          log.debug(u'Feature {feature} is off, aborting request'.format(feature=feature))
          abort(404)

      return func(*args, **kwargs)
    return wrapped
  return _is_active_feature