|
30 | 30 | JSONResponse, |
31 | 31 | SchemaJSONResponse, |
32 | 32 | ) |
33 | | -from tifeatures.settings import APISettings |
34 | 33 |
|
35 | 34 | from fastapi import APIRouter, Depends, Path, Query |
36 | 35 |
|
|
39 | 38 | from starlette.responses import StreamingResponse |
40 | 39 | from starlette.templating import Jinja2Templates, _TemplateResponse |
41 | 40 |
|
42 | | -settings = APISettings() |
43 | | - |
44 | | -# custom template directory |
45 | | -templates_location: List[Any] = ( |
46 | | - [jinja2.FileSystemLoader(settings.template_directory)] |
47 | | - if settings.template_directory |
48 | | - else [] |
49 | | -) |
50 | | -# default template directory |
51 | | -templates_location.append(jinja2.PackageLoader(__package__, "templates")) |
52 | | - |
53 | | -templates = Jinja2Templates( |
54 | | - directory="", # we need to set a dummy directory variable, see https://github.com/encode/starlette/issues/1214 |
55 | | - loader=jinja2.ChoiceLoader(templates_location), |
| 41 | +DEFAULT_TEMPLATES = Jinja2Templates( |
| 42 | + directory="", |
| 43 | + loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]), |
56 | 44 | ) |
57 | 45 |
|
58 | 46 |
|
@@ -96,6 +84,10 @@ class Endpoints: |
96 | 84 | # e.g if you mount the route with `/foo` prefix, set router_prefix to foo |
97 | 85 | router_prefix: str = "" |
98 | 86 |
|
| 87 | + title: str = "TiFeatures" |
| 88 | + |
| 89 | + templates: Jinja2Templates = DEFAULT_TEMPLATES |
| 90 | + |
99 | 91 | def __post_init__(self): |
100 | 92 | """Post Init: register route and configure specific options.""" |
101 | 93 | self.register_landing() |
@@ -135,7 +127,7 @@ def _create_html_response( |
135 | 127 | if self.router_prefix: |
136 | 128 | baseurl += self.router_prefix |
137 | 129 |
|
138 | | - return templates.TemplateResponse( |
| 130 | + return self.templates.TemplateResponse( |
139 | 131 | f"{template_name}.html", |
140 | 132 | { |
141 | 133 | "request": request, |
@@ -173,7 +165,7 @@ def landing( |
173 | 165 | ): |
174 | 166 | """Get conformance.""" |
175 | 167 | data = model.Landing( |
176 | | - title=settings.name, |
| 168 | + title=self.title, |
177 | 169 | links=[ |
178 | 170 | model.Link( |
179 | 171 | title="Landing Page", |
|
0 commit comments