https://dev.kronoz.win/r/marzneshin.git
| 1 |
a47eb4c |
Dawsh |
2y ago |
from datetime import datetime |
| 2 |
a47eb4c |
Dawsh |
2y ago |
from typing import Union |
| 3 |
a47eb4c |
Dawsh |
2y ago |
|
| 4 |
a47eb4c |
Dawsh |
2y ago |
import jinja2 |
| 5 |
a47eb4c |
Dawsh |
2y ago |
|
| 6 |
a47eb4c |
Dawsh |
2y ago |
from config import CUSTOM_TEMPLATES_DIRECTORY |
| 7 |
a47eb4c |
Dawsh |
2y ago |
from .filters import CUSTOM_FILTERS |
| 8 |
a47eb4c |
Dawsh |
2y ago |
|
| 9 |
a47eb4c |
Dawsh |
2y ago |
template_directories = ["app/templates"] |
| 10 |
a47eb4c |
Dawsh |
2y ago |
if CUSTOM_TEMPLATES_DIRECTORY: |
| 11 |
a47eb4c |
Dawsh |
2y ago |
# User's templates have priority over default templates |
| 12 |
a47eb4c |
Dawsh |
2y ago |
template_directories.insert(0, CUSTOM_TEMPLATES_DIRECTORY) |
| 13 |
a47eb4c |
Dawsh |
2y ago |
|
| 14 |
a47eb4c |
Dawsh |
2y ago |
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_directories)) |
| 15 |
a47eb4c |
Dawsh |
2y ago |
env.filters.update(CUSTOM_FILTERS) |
| 16 |
01cdf2e |
Dawsh |
2y ago |
env.globals["now"] = datetime.utcnow |
| 17 |
a47eb4c |
Dawsh |
2y ago |
|
| 18 |
a47eb4c |
Dawsh |
2y ago |
|
| 19 |
a47eb4c |
Dawsh |
2y ago |
def render_template(template: str, context: Union[dict, None] = None) -> str: |
| 20 |
a47eb4c |
Dawsh |
2y ago |
return env.get_template(template).render(context or {}) |