2222import uuid
2323from collections import defaultdict
2424from collections .abc import Iterable , Iterator
25- from typing import Any , Protocol , cast
25+ from typing import Any , Protocol
2626
2727from jinja2 .runtime import Macro
2828from markupsafe import Markup
@@ -311,11 +311,12 @@ def switch_theme(name: str, config: Any):
311311
312312 next_name = name
313313 enabled_themes = {next_name }
314- template_paths = []
315314 while theme := themes .get (next_name ):
316- template_paths .append (os .path .join (theme .path , "templates" ))
317315 relpath = os .path .relpath (theme .path , os .path .dirname (__file__ ))
318316
317+ if os .path .isdir (os .path .join (theme .path , "templates" )):
318+ tk .add_template_directory (config , os .path .join (relpath , "templates" ))
319+
319320 if os .path .isdir (os .path .join (theme .path , "assets" )):
320321 tk .add_resource (os .path .join (relpath , "assets" ), f"theming/{ next_name } " )
321322
@@ -335,14 +336,3 @@ def switch_theme(name: str, config: Any):
335336 else :
336337 msg = f"Theme '{ next_name } ' is not recognised."
337338 raise CkanConfigurationException (msg )
338-
339- log .info ("Re-loading templates from %s" , template_paths )
340-
341- if "plugin_template_paths" in config :
342- template_paths = cast (list [str ], config ["plugin_template_paths" ]) + template_paths
343-
344- if extra_template_paths := cast (str , config ["extra_template_paths" ]):
345- # must be first for them to override defaults
346- template_paths = extra_template_paths .split ("," ) + template_paths
347-
348- config ["computed_template_paths" ] = template_paths
0 commit comments