Make site_branding tag work with Django 4.0

A test for site_branding tag starts to fail with Django 4.0.
It seems to happen as settings.SITE_BRANDING is _("Horizon") and
a translation marker _() is no longer evaluated during rendering.

As a solution, this commit changes the implementation of
site_branding tag to use "simple_tag" method
as django.template.Library.simple_tag() [1] seems to handle
an i18n-ed string properly.

[1] https://docs.djangoproject.com/en/4.0/howto/custom-template-tags/#simple-tags

Closes-Bug: #1980214
Change-Id: I6fdfffbeef2b405da21289d37722e3f068e27fea
This commit is contained in:
Akihiro Motoki 2022-07-28 04:29:58 +09:00 committed by Vishal Manchanda
parent 09d0975ee0
commit b893bcdee3
1 changed files with 3 additions and 8 deletions

View File

@ -27,14 +27,9 @@ from django import template
register = template.Library()
class SiteBrandingNode(template.Node):
def render(self, context):
return settings.SITE_BRANDING
@register.tag
def site_branding(parser, token):
return SiteBrandingNode()
@register.simple_tag
def site_branding():
return settings.SITE_BRANDING
@register.tag