Skip to content

Commit b982a1d

Browse files
committed
Handle jinja2 renamed context decorators
Jinja2 v3.0 renamed contextfilter to pass_context. Put some code in that handles both the v3 and v2 name at the same time, as a first step towards supporting jinja2 v3.
1 parent aa7967d commit b982a1d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

postgresqleu/confreg/jinjafunc.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
import jinja2
2828
import jinja2.sandbox
29+
try:
30+
from jinja2 import pass_context
31+
except ImportError:
32+
# Try Jinja2 2.x version
33+
from jinja2 import contextfilter as pass_context
2934
import markdown
3035

3136

@@ -259,12 +264,12 @@ def _svgparagraph():
259264
return '<text x="{}" y="{}">{}</text>'.format(x, y, "\n".join(_svgparagraph()))
260265

261266

262-
@jinja2.contextfilter
267+
@pass_context
263268
def filter_applymacro(context, obj, macroname):
264269
return context.resolve(macroname)(obj)
265270

266271

267-
@jinja2.contextfilter
272+
@pass_context
268273
def filter_lookup(context, name, default=None):
269274
if not name:
270275
if default is not None:
@@ -285,7 +290,7 @@ def filter_lookup(context, name, default=None):
285290

286291
# Unpack a social media link for the specific social media being rendered for.
287292
# This filter is *not* enabled by default.
288-
@jinja2.contextfilter
293+
@pass_context
289294
def filter_social(context, attr):
290295
if not context.get('messaging', None):
291296
return None
@@ -296,7 +301,7 @@ def filter_social(context, attr):
296301
# Get social media profiles including links from a structure.
297302
# Returns a list of (provider, handle, link) for each configured
298303
# social media identity.
299-
@jinja2.contextfilter
304+
@pass_context
300305
def filter_social_links(context, attr):
301306
if attr:
302307
for k, v in attr.items():

tools/deploystatic/deploystatic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
import jinja2
2222
import jinja2.sandbox
23+
try:
24+
from jinja2 import pass_context
25+
except ImportError:
26+
# Try Jinja2 2.x version
27+
from jinja2 import contextfilter as pass_context
2328

2429
import markdown
2530

@@ -75,7 +80,7 @@ def filter_slugify(value):
7580

7681
# Create social links. In the main site this is dynamic, this limited
7782
# implementation supports just twitter and mastodon.
78-
@jinja2.contextfilter
83+
@pass_context
7984
def filter_social_links(context, attr):
8085
if attr:
8186
for k, v in attr.items():

0 commit comments

Comments
 (0)