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