app.jinja_env.filters.update({ # slug "slug": utils.slugify, # Transform an int to comma "int_with_comma": humanize.intcomma, # Show the date ago: Today, yesterday, July 27 (without year in same year), July 15 2014 "date_since": humanize.naturaldate, # To show the time ago: 3 min ago, 2 days ago, 1 year 7 days ago "time_since": humanize.naturaltime, # Return a mardown to HTML "markdown": markdown_ext.html, # Create a Table of Content of the Markdown "markdown_toc": markdown_ext.toc }) init_app(_setup) # ------------------------------------------------------------------------------ # Session # # It uses KV session to allow multiple backend for the session def _session(app): store = None uri = app.config.get("SESSION_URI") if uri: parse_uri = urlparse(uri) scheme = parse_uri.scheme username = parse_uri.username password = parse_uri.password hostname = parse_uri.hostname
sorted(sub_menu), _kwargs )) else: menu_list += sub_menu return sorted(menu_list) def init_app(self, app): @app.before_request def p(*args, **kwargs): if request.endpoint not in ["static", None]: # (order, Name, sub_menu, **kargs, hidden_submenu) Magic.g(MENU=menu.render()) menu = Menu() init_app(menu.init_app) # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ def require_user_roles(*roles): """ A decorator to check if user has any of the roles specified @require_user_roles('superadmin', 'admin') def fn(): pass """ def wrapper(f): @functools.wraps(f)
if _kw and "show" in _kw and _nav_menu_test_show(_kw["show"]) is False: continue sub_menu.append(s) _kwargs = menu["kwargs"] _kwargs["__hidden"] = sorted(sub_menu_hidden) menu_list.append(( menu["order"], menu["name"], sorted(sub_menu), _kwargs )) WebPortfolio.g(NAV_MENU=sorted(menu_list)) init_app(_nav_menu_init) # ------------------------------------------------------------------------------ def with_user_roles(*roles): """ A decorator to check if user has any of the roles specified @with_user_roles('superadmin', 'admin') def fn(): pass """ def wrapper(f): @functools.wraps(f) def wrapped(*args, **kwargs): if ext.user_authenticated():