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