Show More
@@ -1,109 +1,109 b'' | |||||
1 |
|
1 | |||
2 |
|
2 | |||
3 | # Copyright (C) 2017-2020 RhodeCode GmbH |
|
3 | # Copyright (C) 2017-2020 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 | from uuid import uuid4 |
|
21 | from uuid import uuid4 | |
22 | import pyramid.testing |
|
22 | import pyramid.testing | |
23 | from pyramid.decorator import reify |
|
23 | from pyramid.decorator import reify | |
24 | from pyramid.request import Request as _Request |
|
24 | from pyramid.request import Request as _Request | |
25 | from rhodecode.translation import _ as tsf |
|
25 | from rhodecode.lib.type_utils import StrictAttributeDict | |
26 | from rhodecode.lib.utils2 import StrictAttributeDict |
|
|||
27 |
|
26 | |||
28 |
|
27 | |||
29 | class TemplateArgs(StrictAttributeDict): |
|
28 | class TemplateArgs(StrictAttributeDict): | |
30 | pass |
|
29 | pass | |
31 |
|
30 | |||
32 |
|
31 | |||
33 | # Base Class with DummyMethods, testing / CLI scripts |
|
32 | # Base Class with DummyMethods, testing / CLI scripts | |
34 | class RequestBase(object): |
|
33 | class RequestBase(object): | |
35 | _req_id_bucket = list() |
|
34 | _req_id_bucket = list() | |
36 | _call_context = TemplateArgs() |
|
35 | _call_context = TemplateArgs() | |
37 | _call_context.visual = TemplateArgs() |
|
36 | _call_context.visual = TemplateArgs() | |
38 | _call_context.visual.show_sha_length = 12 |
|
37 | _call_context.visual.show_sha_length = 12 | |
39 | _call_context.visual.show_revision_number = True |
|
38 | _call_context.visual.show_revision_number = True | |
40 |
|
39 | |||
41 | @reify |
|
40 | @reify | |
42 | def req_id(self): |
|
41 | def req_id(self): | |
43 | return str(uuid4()) |
|
42 | return str(uuid4()) | |
44 |
|
43 | |||
45 | @property |
|
44 | @property | |
46 | def req_id_bucket(self): |
|
45 | def req_id_bucket(self): | |
47 | return self._req_id_bucket |
|
46 | return self._req_id_bucket | |
48 |
|
47 | |||
49 | def req_id_records_init(self): |
|
48 | def req_id_records_init(self): | |
50 | self._req_id_bucket = list() |
|
49 | self._req_id_bucket = list() | |
51 |
|
50 | |||
52 | def translate(self, *args, **kwargs): |
|
51 | def translate(self, *args, **kwargs): | |
53 | raise NotImplementedError() |
|
52 | raise NotImplementedError() | |
54 |
|
53 | |||
55 | def plularize(self, *args, **kwargs): |
|
54 | def plularize(self, *args, **kwargs): | |
56 | raise NotImplementedError() |
|
55 | raise NotImplementedError() | |
57 |
|
56 | |||
58 | def get_partial_renderer(self, tmpl_name): |
|
57 | def get_partial_renderer(self, tmpl_name): | |
59 | raise NotImplementedError() |
|
58 | raise NotImplementedError() | |
60 |
|
59 | |||
61 | @property |
|
60 | @property | |
62 | def call_context(self): |
|
61 | def call_context(self): | |
63 | return self._call_context |
|
62 | return self._call_context | |
64 |
|
63 | |||
65 | def set_call_context(self, new_context): |
|
64 | def set_call_context(self, new_context): | |
66 | self._call_context = new_context |
|
65 | self._call_context = new_context | |
67 |
|
66 | |||
68 |
|
67 | |||
69 | # for thin non-web/cli etc |
|
68 | # for thin non-web/cli etc | |
70 | class ThinRequest(RequestBase, pyramid.testing.DummyRequest): |
|
69 | class ThinRequest(RequestBase, pyramid.testing.DummyRequest): | |
71 |
|
70 | |||
72 | def translate(self, msg): |
|
71 | def translate(self, msg): | |
73 | return msg |
|
72 | return msg | |
74 |
|
73 | |||
75 | def plularize(self, singular, plural, n): |
|
74 | def plularize(self, singular, plural, n): | |
76 | return singular |
|
75 | return singular | |
77 |
|
76 | |||
78 | def get_partial_renderer(self, tmpl_name): |
|
77 | def get_partial_renderer(self, tmpl_name): | |
79 | from rhodecode.lib.partial_renderer import get_partial_renderer |
|
78 | from rhodecode.lib.partial_renderer import get_partial_renderer | |
80 | return get_partial_renderer(request=self, tmpl_name=tmpl_name) |
|
79 | return get_partial_renderer(request=self, tmpl_name=tmpl_name) | |
81 |
|
80 | |||
82 |
|
81 | |||
83 | # for real-web-based |
|
82 | # for real-web-based | |
84 | class RealRequest(RequestBase, _Request): |
|
83 | class RealRequest(RequestBase, _Request): | |
85 | def get_partial_renderer(self, tmpl_name): |
|
84 | def get_partial_renderer(self, tmpl_name): | |
86 | from rhodecode.lib.partial_renderer import get_partial_renderer |
|
85 | from rhodecode.lib.partial_renderer import get_partial_renderer | |
87 | return get_partial_renderer(request=self, tmpl_name=tmpl_name) |
|
86 | return get_partial_renderer(request=self, tmpl_name=tmpl_name) | |
88 |
|
87 | |||
89 | def request_count(self): |
|
88 | def request_count(self): | |
90 | from rhodecode.lib.request_counter import get_request_counter |
|
89 | from rhodecode.lib.request_counter import get_request_counter | |
91 | return get_request_counter() |
|
90 | return get_request_counter() | |
92 |
|
91 | |||
93 | def plularize(self, *args, **kwargs): |
|
92 | def plularize(self, *args, **kwargs): | |
94 | return self.localizer.pluralize(*args, **kwargs) |
|
93 | return self.localizer.pluralize(*args, **kwargs) | |
95 |
|
94 | |||
96 | def translate(self, *args, **kwargs): |
|
95 | def translate(self, *args, **kwargs): | |
97 | localizer = self.localizer |
|
96 | localizer = self.localizer | |
|
97 | from rhodecode.translation import _ as tsf | |||
98 |
|
98 | |||
99 | def auto_translate(*_args, **_kwargs): |
|
99 | def auto_translate(*_args, **_kwargs): | |
100 | return localizer.translate(tsf(*_args, **_kwargs)) |
|
100 | return localizer.translate(tsf(*_args, **_kwargs)) | |
101 |
|
101 | |||
102 | return auto_translate(*args, **kwargs) |
|
102 | return auto_translate(*args, **kwargs) | |
103 |
|
103 | |||
104 |
|
104 | |||
105 | class Request(RealRequest): |
|
105 | class Request(RealRequest): | |
106 | """ |
|
106 | """ | |
107 | This is the main request object used in web-context |
|
107 | This is the main request object used in web-context | |
108 | """ |
|
108 | """ | |
109 | pass |
|
109 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now