def p(*args, **kwargs): # (order, Name, sub_menu, **kargs, hidden_submenu) menu_list = [] menu_index = 0 for _, menu in _NAV_MENU_STACK.items(): menu_index += 1 menu["kwargs"]["__index"] = menu_index menu["kwargs"]["__active"] = False # Filter out menu that should not be shown _kw = menu["kwargs"] if _kw and "show" in _kw and _nav_menu_test_show(_kw["show"]) is False: continue sub_menu = [] sub_menu_hidden = [] # Save all the hidden submenu for s in menu["sub_menu"]: if s[2] == request.endpoint: s[3]["__active"] = True menu["kwargs"]["__active"] = True sub_menu_hidden.append(s) _kw = s[3] 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))
def _setup(app): def sanity_check(): keys = [ "SECRET_KEY", "APPLICATION_ADMIN_EMAIL", "MAILER_URI", "MAILER_SENDER", "MODULE_CONTACT_PAGE_EMAIL", "RECAPTCHA_SITE_KEY", "RECAPTCHA_SECRET_KEY" ] for k in keys: if k not in app.config \ or not app.config.get(k) \ or app.config.get(k).strip() == "": msg = "Config [ %s ] value is not set or empty" % k app.logger.warn(msg) sanity_check() WebPortfolio.g(APPLICATION_NAME=app.config.get("APPLICATION_NAME"), APPLICATION_VERSION=app.config.get("APPLICATION_VERSION"), APPLICATION_URL=app.config.get("APPLICATION_URL"), APPLICATION_GOOGLE_ANALYTICS_ID=app.config.get("APPLICATION_GOOGLE_ANALYTICS_ID")) # Setup filters @app.template_filter('datetime') def format_datetime(dt, format="%m/%d/%Y"): return "" if not dt else dt.strftime(format) @app.template_filter('strip_decimal') def strip_decimal(amount): return amount.split(".")[0] @app.template_filter('bool_to_yes') def bool_to_yes(b): return "Yes" if b else "No" @app.template_filter('bool_to_int') def bool_to_int(b): return 1 if b else 0 @app.template_filter('nl2br') def nl2br(s): """ {{ s|nl2br }} Convert newlines into <p> and <br />s. """ if not isinstance(s, basestring): s = str(s) s = re.sub(r'\r\n|\r|\n', '\n', s) paragraphs = re.split('\n{2,}', s) paragraphs = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paragraphs] return '\n\n'.join(paragraphs) # More filters 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": wp_markdown.html, # Create a Table of Content of the Markdown "markdown_toc": wp_markdown.toc })