Show More
@@ -1,92 +1,93 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # Model for RhodeCode settings |
|
3 | # Model for RhodeCode settings | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; version 2 |
|
8 | # as published by the Free Software Foundation; version 2 | |
9 | # of the License or (at your opinion) any later version of the license. |
|
9 | # of the License or (at your opinion) any later version of the license. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. |
|
19 | # MA 02110-1301, USA. | |
20 | """ |
|
20 | """ | |
21 | Created on Nov 17, 2010 |
|
21 | Created on Nov 17, 2010 | |
22 | Model for RhodeCode |
|
22 | Model for RhodeCode | |
23 | :author: marcink |
|
23 | :author: marcink | |
24 | """ |
|
24 | """ | |
25 |
|
25 | |||
26 | from rhodecode.lib import helpers as h |
|
26 | from rhodecode.lib import helpers as h | |
27 | from rhodecode.model import BaseModel |
|
27 | from rhodecode.model import BaseModel | |
28 | from rhodecode.model.caching_query import FromCache |
|
28 | from rhodecode.model.caching_query import FromCache | |
29 | from rhodecode.model.db import RhodeCodeSettings |
|
29 | from rhodecode.model.db import RhodeCodeSettings | |
30 | from sqlalchemy.orm import joinedload |
|
30 | from sqlalchemy.orm import joinedload | |
31 | import logging |
|
31 | import logging | |
32 |
|
32 | |||
33 | log = logging.getLogger(__name__) |
|
33 | log = logging.getLogger(__name__) | |
34 |
|
34 | |||
35 | class SettingsModel(BaseModel): |
|
35 | class SettingsModel(BaseModel): | |
36 | """ |
|
36 | """ | |
37 | Settings model |
|
37 | Settings model | |
38 | """ |
|
38 | """ | |
39 |
|
39 | |||
40 | def get(self, settings_key, cache=False): |
|
40 | def get(self, settings_key, cache=False): | |
41 | r = self.sa.query(RhodeCodeSettings)\ |
|
41 | r = self.sa.query(RhodeCodeSettings)\ | |
42 | .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar() |
|
42 | .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar() | |
43 | if cache: |
|
43 | if cache: | |
44 | r = r.options(FromCache("sql_cache_short", |
|
44 | r = r.options(FromCache("sql_cache_short", | |
45 | "get_setting_%s" % settings_key)) |
|
45 | "get_setting_%s" % settings_key)) | |
46 | return r |
|
46 | return r | |
47 |
|
47 | |||
48 | def get_app_settings(self): |
|
48 | def get_app_settings(self, cache=False): | |
49 | """Get's config from database, each config key is prefixed with |
|
49 | """Get's config from database, each config key is prefixed with | |
50 | 'rhodecode_' prefix, than global pylons config is updated with such |
|
50 | 'rhodecode_' prefix, than global pylons config is updated with such | |
51 | keys |
|
51 | keys | |
52 | """ |
|
52 | """ | |
53 |
|
53 | |||
54 |
ret = self.sa.query(RhodeCodeSettings) |
|
54 | ret = self.sa.query(RhodeCodeSettings) | |
55 | .options(FromCache("sql_cache_short", |
|
55 | ||
56 | "get_hg_settings")).all() |
|
56 | if cache: | |
|
57 | ret = ret.options(FromCache("sql_cache_short", "get_hg_settings")) | |||
57 |
|
58 | |||
58 | if not ret: |
|
59 | if not ret: | |
59 | raise Exception('Could not get application settings !') |
|
60 | raise Exception('Could not get application settings !') | |
60 | settings = {} |
|
61 | settings = {} | |
61 | for each in ret: |
|
62 | for each in ret: | |
62 | settings['rhodecode_' + each.app_settings_name] = each.app_settings_value |
|
63 | settings['rhodecode_' + each.app_settings_name] = each.app_settings_value | |
63 |
|
64 | |||
64 | return settings |
|
65 | return settings | |
65 |
|
66 | |||
66 | def get_ldap_settings(self): |
|
67 | def get_ldap_settings(self): | |
67 | """ |
|
68 | """ | |
68 | Returns ldap settings from database |
|
69 | Returns ldap settings from database | |
69 | :returns: |
|
70 | :returns: | |
70 | ldap_active |
|
71 | ldap_active | |
71 | ldap_host |
|
72 | ldap_host | |
72 | ldap_port |
|
73 | ldap_port | |
73 | ldap_ldaps |
|
74 | ldap_ldaps | |
74 | ldap_dn_user |
|
75 | ldap_dn_user | |
75 | ldap_dn_pass |
|
76 | ldap_dn_pass | |
76 | ldap_base_dn |
|
77 | ldap_base_dn | |
77 | """ |
|
78 | """ | |
78 |
|
79 | |||
79 | r = self.sa.query(RhodeCodeSettings)\ |
|
80 | r = self.sa.query(RhodeCodeSettings)\ | |
80 | .filter(RhodeCodeSettings.app_settings_name\ |
|
81 | .filter(RhodeCodeSettings.app_settings_name\ | |
81 | .startswith('ldap_'))\ |
|
82 | .startswith('ldap_'))\ | |
82 | .all() |
|
83 | .all() | |
83 |
|
84 | |||
84 | fd = {} |
|
85 | fd = {} | |
85 |
|
86 | |||
86 | for row in r: |
|
87 | for row in r: | |
87 | v = row.app_settings_value |
|
88 | v = row.app_settings_value | |
88 | if v in ['0', '1']: |
|
89 | if v in ['0', '1']: | |
89 | v = v == '1' |
|
90 | v = v == '1' | |
90 | fd.update({row.app_settings_name:v}) |
|
91 | fd.update({row.app_settings_name:v}) | |
91 |
|
92 | |||
92 | return fd |
|
93 | return fd |
General Comments 0
You need to be logged in to leave comments.
Login now