|
@@ -3,11 +3,14 @@
|
3
|
3
|
import jinja2
|
4
|
4
|
|
5
|
5
|
import settings
|
6
|
|
-from . import api_lodel_templates
|
|
6
|
+from .api import api_lodel_templates
|
|
7
|
+from .exceptions import NotAllowedCustomAPIKeyError
|
7
|
8
|
|
8
|
9
|
|
9
|
10
|
class TemplateLoader(object):
|
10
|
11
|
|
|
12
|
+ __reserved_template_keys = ['lodel']
|
|
13
|
+
|
11
|
14
|
## @brief Initializes a template loader
|
12
|
15
|
#
|
13
|
16
|
# @param search_path str : the base path from which the templates are searched. To use absolute paths, you can set
|
|
@@ -39,6 +42,15 @@ class TemplateLoader(object):
|
39
|
42
|
# Extra modules are loaded
|
40
|
43
|
if template_extra is not None:
|
41
|
44
|
for extra in template_extra:
|
|
45
|
+ if not self.__is_allowed_template_key(extra[0]):
|
|
46
|
+ raise NotAllowedCustomAPIKeyError("The name 'lodel' is a reserved one for the loaded APIs in templates")
|
42
|
47
|
template.globals[extra[0]] = extra[1]
|
43
|
48
|
|
44
|
49
|
return template.render(template_vars)
|
|
50
|
+
|
|
51
|
+ ## @brief Checks if the key used for the template is allowed
|
|
52
|
+ #
|
|
53
|
+ # @param key str
|
|
54
|
+ # @return bool
|
|
55
|
+ def __is_allowed_template_key(self, key):
|
|
56
|
+ return False if key in self.__class__.__reserved_template_keys else True
|