]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Allow instantiating template dataclasses in jinja2 templates
authorNicki Křížek <nicki@isc.org>
Wed, 1 Apr 2026 17:42:38 +0000 (19:42 +0200)
committerNicki Křížek <nicki@isc.org>
Thu, 28 May 2026 14:52:24 +0000 (16:52 +0200)
In some cases, the template data might need to be set directly in the
jinja2 templates using `{% set %}`. Expose the template dataclasses to
the templates so we can use these existing classes, rather than creating
ad-hoc data containers.

(cherry picked from commit dddb0673517ccbba50941d91dec3c55e1f7f52b4)

bin/tests/system/isctest/template.py

index b90054e4a5f062b7fe299c740d0a1393e324a1ff..130d36306938ba692c33c929436d694124339bbc 100644 (file)
@@ -56,12 +56,17 @@ class TemplateEngine:
                 pytest.skip("jinja2 not found")
 
             loader = jinja2.FileSystemLoader(str(self.directory))
-            return jinja2.Environment(
+            self._j2env = jinja2.Environment(
                 loader=loader,
                 undefined=jinja2.StrictUndefined,
                 variable_start_string="@",
                 variable_end_string="@",
             )
+            # allow instantiating the template dataclasses in jinja2 templates when
+            # using {% set %}
+            self._j2env.globals["Nameserver"] = Nameserver
+            self._j2env.globals["TrustAnchor"] = TrustAnchor
+            self._j2env.globals["Zone"] = Zone
         return self._j2env
 
     def render(