From ef1609efc2c667cb9ebe86f6f0bf503696310e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 21 Dec 2017 12:58:06 +0100 Subject: [PATCH] Added abs_url() Jinja function for proper absolute URLs abs_url(x) is a shortcut for url_for(x, _external=True, _schema=app.config['SCHEMA']), and should be used for all URLs that should include the hostname and schema. --- pillar/__init__.py | 2 +- pillar/web/jinja.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pillar/__init__.py b/pillar/__init__.py index 0ab8ab6c..2627692e 100644 --- a/pillar/__init__.py +++ b/pillar/__init__.py @@ -425,7 +425,7 @@ class PillarServer(BlinkerCompatibleEve): custom_jinja_loader = jinja2.ChoiceLoader(paths_list) self.jinja_loader = custom_jinja_loader - pillar.web.jinja.setup_jinja_env(self.jinja_env) + pillar.web.jinja.setup_jinja_env(self.jinja_env, self.config) # Register context processors from extensions for ext in self.pillar_extensions.values(): diff --git a/pillar/web/jinja.py b/pillar/web/jinja.py index 04a7c280..76d6a219 100644 --- a/pillar/web/jinja.py +++ b/pillar/web/jinja.py @@ -1,5 +1,6 @@ """Our custom Jinja filters and other template stuff.""" +import functools import logging import typing @@ -146,7 +147,7 @@ def do_yesno(value, arg=None): return no -def setup_jinja_env(jinja_env): +def setup_jinja_env(jinja_env, app_config: dict): jinja_env.filters['pretty_date'] = format_pretty_date jinja_env.filters['pretty_date_time'] = format_pretty_date_time jinja_env.filters['undertitle'] = format_undertitle @@ -157,5 +158,8 @@ def setup_jinja_env(jinja_env): jinja_env.filters['yesno'] = do_yesno jinja_env.filters['repr'] = repr jinja_env.globals['url_for_node'] = do_url_for_node + jinja_env.globals['abs_url'] = functools.partial(flask.url_for, + _external=True, + _scheme=app_config['SCHEME']) jinja_env.globals['session'] = flask.session jinja_env.globals['current_user'] = flask_login.current_user