Files
@ 6832ef664673
Branch filter:
Location: kallithea/rhodecode/model/settings.py
6832ef664673
3.1 KiB
text/x-python
source code cleanup: remove trailing white space, normalize file endings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | # -*- coding: utf-8 -*-
"""
rhodecode.model.settings
~~~~~~~~~~~~~~~~~~~~~~~~
Settings model for RhodeCode
:created on Nov 17, 2010
:author: marcink
:copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
:license: GPLv3, see COPYING for more details.
"""
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License or (at your opinion) any later version of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import logging
from rhodecode.model import BaseModel
from rhodecode.model.caching_query import FromCache
from rhodecode.model.db import RhodeCodeSettings
log = logging.getLogger(__name__)
class SettingsModel(BaseModel):
"""
Settings model
"""
def get(self, settings_key, cache=False):
r = self.sa.query(RhodeCodeSettings)\
.filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
if cache:
r = r.options(FromCache("sql_cache_short",
"get_setting_%s" % settings_key))
return r
def get_app_settings(self, cache=False):
"""Get's config from database, each config key is prefixed with
'rhodecode_' prefix, than global pylons config is updated with such
keys
"""
ret = self.sa.query(RhodeCodeSettings)
if cache:
ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
if not ret:
raise Exception('Could not get application settings !')
settings = {}
for each in ret:
settings['rhodecode_' + each.app_settings_name] = each.app_settings_value
return settings
def get_ldap_settings(self):
"""
Returns ldap settings from database
:returns:
ldap_active
ldap_host
ldap_port
ldap_ldaps
ldap_tls_reqcert
ldap_dn_user
ldap_dn_pass
ldap_base_dn
ldap_filter
ldap_search_scope
ldap_attr_login
ldap_attr_firstname
ldap_attr_lastname
ldap_attr_email
"""
# ldap_search_scope
r = self.sa.query(RhodeCodeSettings)\
.filter(RhodeCodeSettings.app_settings_name\
.startswith('ldap_'))\
.all()
fd = {}
for row in r:
v = row.app_settings_value
if v in ['true', 'yes', 'on', 'y', 't', '1']:
v = True
elif v in ['false', 'no', 'off', 'n', 'f', '0']:
v = False
fd.update({row.app_settings_name:v})
return fd
|