| 1 |
""" |
| 2 |
Wrapper for loading templates from a plain Python dict. |
| 3 |
""" |
| 4 |
|
| 5 |
from django.template import Origin, TemplateDoesNotExist |
| 6 |
|
| 7 |
from .base import Loader as BaseLoader |
| 8 |
|
| 9 |
|
| 10 |
class Loader(BaseLoader): |
| 11 |
def __init__(self, engine, templates_dict): |
| 12 |
self.templates_dict = templates_dict |
| 13 |
super().__init__(engine) |
| 14 |
|
| 15 |
def get_contents(self, origin): |
| 16 |
try: |
| 17 |
return self.templates_dict[origin.name] |
| 18 |
except KeyError: |
| 19 |
raise TemplateDoesNotExist(origin) |
| 20 |
|
| 21 |
def get_template_sources(self, template_name): |
| 22 |
yield Origin( |
| 23 |
name=template_name, |
| 24 |
template_name=template_name, |
| 25 |
loader=self, |
| 26 |
) |