mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Move utilities.utils.render_jinja2() to utilities.jinja2
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
from django.apps import apps
|
||||
from jinja2 import BaseLoader, TemplateNotFound
|
||||
from jinja2.meta import find_referenced_templates
|
||||
from jinja2.sandbox import SandboxedEnvironment
|
||||
|
||||
from netbox.config import get_config
|
||||
|
||||
__all__ = (
|
||||
'DataFileLoader',
|
||||
@ -35,3 +38,16 @@ class DataFileLoader(BaseLoader):
|
||||
|
||||
def cache_templates(self, templates):
|
||||
self._template_cache.update(templates)
|
||||
|
||||
|
||||
#
|
||||
# Utility functions
|
||||
#
|
||||
|
||||
def render_jinja2(template_code, context):
|
||||
"""
|
||||
Render a Jinja2 template with the provided context. Return the rendered content.
|
||||
"""
|
||||
environment = SandboxedEnvironment()
|
||||
environment.filters.update(get_config().JINJA2_FILTERS)
|
||||
return environment.from_string(source=template_code).render(**context)
|
||||
|
Reference in New Issue
Block a user