forked from openlabs/trytond-nereid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.py
33 lines (28 loc) · 1.17 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import Pool
__all__ = ['ContextProcessors']
class ContextProcessors(ModelSQL, ModelView):
"Temlate Context Processor Registry"
__name__ = 'nereid.template.context_processor'
_rec_name = 'method'
method = fields.Char('Method', required=True,
help="Context processor method in <model>.<method>")
model = fields.Char('Model',
help="This will restrict the loading when URLs with"
" the model are called")
@classmethod
def get_processors(cls):
"""
Return the list of processors. Separate function
since its important to have caching on this
"""
result = { }
ctx_processors = cls.search([])
for ctx_proc in ctx_processors:
model, method = ctx_proc.method.rsplit('.', 1)
ctx_proc_as_func = getattr(Pool().get(model), method)
result.setdefault(ctx_proc.model or None, []).append(
ctx_proc_as_func)
return result