##// END OF EJS Templates
pyramid: base view improvements
marcink -
r1534:f94cdb1c default
parent child Browse files
Show More
@@ -1,66 +1,78 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2017 RhodeCode GmbH
3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22 from pylons import tmpl_context as c
22 from pylons import tmpl_context as c
23
23
24 from rhodecode.lib.utils2 import StrictAttributeDict
24 from rhodecode.lib.utils2 import StrictAttributeDict
25
25
26 log = logging.getLogger(__name__)
26 log = logging.getLogger(__name__)
27
27
28
28
29 ADMIN_PREFIX = '/_admin'
29 ADMIN_PREFIX = '/_admin'
30 STATIC_FILE_PREFIX = '/_static'
30 STATIC_FILE_PREFIX = '/_static'
31
31
32
32
33 class TemplateArgs(StrictAttributeDict):
33 class TemplateArgs(StrictAttributeDict):
34 pass
34 pass
35
35
36
36
37 class BaseAppView(object):
37 class BaseAppView(object):
38
38
39 def __init__(self, context, request):
39 def __init__(self, context, request):
40 self.request = request
40 self.request = request
41 self.context = context
41 self.context = context
42 self.session = request.session
42 self.session = request.session
43 self._rhodecode_user = request.user
43 self._rhodecode_user = request.user # auth user
44
44
45 def _get_local_tmpl_context(self):
45 def _get_local_tmpl_context(self):
46 c = TemplateArgs()
46 c = TemplateArgs()
47 c.auth_user = self.request.user
47 c.auth_user = self.request.user
48 return c
48 return c
49
49
50 def _register_global_c(self, tmpl_args):
50 def _register_global_c(self, tmpl_args):
51 """
51 """
52 Registers attributes to pylons global `c`
52 Registers attributes to pylons global `c`
53 """
53 """
54 # TODO(marcink): remove once pyramid migration is finished
54 # TODO(marcink): remove once pyramid migration is finished
55 for k, v in tmpl_args.items():
55 for k, v in tmpl_args.items():
56 setattr(c, k, v)
56 setattr(c, k, v)
57
57
58 def _get_template_context(self, tmpl_args):
58 def _get_template_context(self, tmpl_args):
59
59
60 self._register_global_c(tmpl_args)
60 self._register_global_c(tmpl_args)
61
61
62 return {
62 return {
63 'defaults': {},
63 'defaults': {},
64 'errors': {},
64 'errors': {},
65 }
65 }
66
66
67 def load_default_context(self):
68 """
69 example:
70
71 def load_default_context(self):
72 c = self._get_local_tmpl_context()
73 c.custom_var = 'foobar'
74 self._register_global_c(c)
75 return c
76 """
77 raise NotImplementedError('Needs implementation in view class')
78
General Comments 0
You need to be logged in to leave comments. Login now