|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | from typing import cast |
2 | | -from jinja2 import pass_context, Template, TemplateRuntimeError |
3 | | -from jinja2.runtime import Context |
| 4 | + |
4 | 5 | from django.utils.module_loading import import_string |
| 6 | +from jinja2 import Template |
| 7 | +from jinja2 import TemplateRuntimeError |
| 8 | +from jinja2 import pass_context |
| 9 | +from jinja2.runtime import Context |
| 10 | + |
5 | 11 | from django_simple_nav.nav import Nav |
6 | 12 |
|
7 | 13 |
|
8 | 14 | @pass_context |
9 | | -def django_simple_nav(context: Context, nav: str | Nav, |
10 | | - template_name: str | None = None) -> str: |
| 15 | +def django_simple_nav( |
| 16 | + context: Context, nav: str | Nav, template_name: str | None = None |
| 17 | +) -> str: |
11 | 18 | """Jinja binding for `django_simple_nav`""" |
12 | 19 | if (loader := context.environment.loader) is None: |
13 | | - raise TemplateRuntimeError('No template loader in Jinja2 environment') |
| 20 | + raise TemplateRuntimeError("No template loader in Jinja2 environment") |
14 | 21 |
|
15 | 22 | if type(nav) is str: |
16 | 23 | try: |
17 | 24 | nav = import_string(nav)() |
18 | 25 | except ImportError as err: |
19 | | - raise TemplateRuntimeError(f'Variable does not exist: {err}') |
| 26 | + raise TemplateRuntimeError(f"Variable does not exist: {err}") |
20 | 27 |
|
21 | 28 | if template_name is None: |
22 | 29 | template_name = cast(Nav, nav).template_name |
23 | 30 | if template_name is None: |
24 | | - raise TemplateRuntimeError('Navigation object has no template') |
| 31 | + raise TemplateRuntimeError("Navigation object has no template") |
25 | 32 |
|
26 | 33 | template: Template = loader.load(context.environment, template_name) |
27 | 34 | return template.render(items=cast(Nav, nav).items) |
0 commit comments