2014-11-16 01:35:02 +08:00
|
|
|
"""
|
|
|
|
Wrapper for loading templates from a plain Python dict.
|
|
|
|
"""
|
|
|
|
|
2015-04-25 03:35:30 +08:00
|
|
|
from django.template import Origin, TemplateDoesNotExist
|
2014-11-16 01:35:02 +08:00
|
|
|
|
|
|
|
from .base import Loader as BaseLoader
|
|
|
|
|
|
|
|
|
|
|
|
class Loader(BaseLoader):
|
|
|
|
|
2014-11-20 06:23:58 +08:00
|
|
|
def __init__(self, engine, templates_dict):
|
2014-11-16 01:35:02 +08:00
|
|
|
self.templates_dict = templates_dict
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(engine)
|
2014-11-16 01:35:02 +08:00
|
|
|
|
2015-03-04 05:48:26 +08:00
|
|
|
def get_contents(self, origin):
|
|
|
|
try:
|
|
|
|
return self.templates_dict[origin.name]
|
|
|
|
except KeyError:
|
|
|
|
raise TemplateDoesNotExist(origin)
|
|
|
|
|
|
|
|
def get_template_sources(self, template_name):
|
|
|
|
yield Origin(
|
|
|
|
name=template_name,
|
|
|
|
template_name=template_name,
|
|
|
|
loader=self,
|
|
|
|
)
|