def p(*args, **kwargs): View.g(MENU=self.render())
def p(*args, **kwargs): if request.endpoint not in ["static", None]: # (order, Name, sub_menu, **kargs, hidden_submenu) View.g(MENU=menu.render())
def _setup(app): def sanity_check(): keys = [ "SECRET_KEY", "APPLICATION_ADMIN_EMAIL", "APPLICATION_CONTACT_EMAIL", "MAILER_URI", "MAILER_SENDER", "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 logging.warning(msg) sanity_check() View.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": markdown_ext.html, # Create a Table of Content of the Markdown "markdown_toc": markdown_ext.toc })