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.
This commit is contained in:
@@ -425,7 +425,7 @@ class PillarServer(BlinkerCompatibleEve):
|
|||||||
custom_jinja_loader = jinja2.ChoiceLoader(paths_list)
|
custom_jinja_loader = jinja2.ChoiceLoader(paths_list)
|
||||||
self.jinja_loader = custom_jinja_loader
|
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
|
# Register context processors from extensions
|
||||||
for ext in self.pillar_extensions.values():
|
for ext in self.pillar_extensions.values():
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
"""Our custom Jinja filters and other template stuff."""
|
"""Our custom Jinja filters and other template stuff."""
|
||||||
|
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ def do_yesno(value, arg=None):
|
|||||||
return no
|
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'] = format_pretty_date
|
||||||
jinja_env.filters['pretty_date_time'] = format_pretty_date_time
|
jinja_env.filters['pretty_date_time'] = format_pretty_date_time
|
||||||
jinja_env.filters['undertitle'] = format_undertitle
|
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['yesno'] = do_yesno
|
||||||
jinja_env.filters['repr'] = repr
|
jinja_env.filters['repr'] = repr
|
||||||
jinja_env.globals['url_for_node'] = do_url_for_node
|
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['session'] = flask.session
|
||||||
jinja_env.globals['current_user'] = flask_login.current_user
|
jinja_env.globals['current_user'] = flask_login.current_user
|
||||||
|
Reference in New Issue
Block a user