##// END OF EJS Templates
Added settings model, and Exceptions lib....
marcink -
r704:26237de9 beta
parent child Browse files
Show More
@@ -0,0 +1,29 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Custom Exceptions modules
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
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
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on Nov 17, 2010
22 Custom Exceptions modules
23 @author: marcink
24 """
25
26 class UsernameError(Exception):pass
27 class PasswordError(Exception):pass
28 class ConnectionError(Exception):pass
29 class LdapImportError(Exception):pass
@@ -0,0 +1,68 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Model for RhodeCode settings
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
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
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on Nov 17, 2010
22 Model for RhodeCode
23 @author: marcink
24 """
25 from rhodecode.lib import helpers as h
26 from rhodecode.model import meta
27 from rhodecode.model.caching_query import FromCache
28 from rhodecode.model.db import RhodeCodeSettings
29 from sqlalchemy.orm import joinedload
30 from sqlalchemy.orm.session import make_transient
31 import logging
32
33 log = logging.getLogger(__name__)
34
35 class SettingsModel(object):
36 """
37 Settings model
38 """
39
40 def __init__(self):
41 self.sa = meta.Session()
42
43
44 def get(self, settings_key, cache=False):
45 r = self.sa.query(RhodeCodeSettings)\
46 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
47 if cache:
48 r = r.options(FromCache("sql_cache_short",
49 "get_setting_%s" % settings_key))
50 return r
51
52
53 def get_ldap_settings(self):
54
55 r = self.sa.query(RhodeCodeSettings)\
56 .filter(RhodeCodeSettings.app_settings_name\
57 .startswith('ldap_'))\
58 .all()
59
60 fd = {}
61
62 for row in r:
63 v = row.app_settings_value
64 if v in ['0', '1']:
65 v = v == '1'
66 fd.update({row.app_settings_name:v})
67
68 return fd
@@ -176,16 +176,13 b' class DbManage(object):'
176 paths.ui_value = path
176 paths.ui_value = path
177
177
178
178
179 hgsettings1 = RhodeCodeSettings()
179 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
180 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
180
181
181 hgsettings1.app_settings_name = 'realm'
182 hgsettings1.app_settings_value = 'RhodeCode authentication'
183
184 hgsettings2 = RhodeCodeSettings()
185 hgsettings2.app_settings_name = 'title'
186 hgsettings2.app_settings_value = 'RhodeCode'
187
182
188 try:
183 try:
184
185
189 self.sa.add(hooks1)
186 self.sa.add(hooks1)
190 self.sa.add(hooks2)
187 self.sa.add(hooks2)
191 self.sa.add(hooks3)
188 self.sa.add(hooks3)
@@ -197,6 +194,12 b' class DbManage(object):'
197 self.sa.add(paths)
194 self.sa.add(paths)
198 self.sa.add(hgsettings1)
195 self.sa.add(hgsettings1)
199 self.sa.add(hgsettings2)
196 self.sa.add(hgsettings2)
197 for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps',
198 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']:
199
200 setting = RhodeCodeSettings(k, '')
201 self.sa.add(setting)
202
200 self.sa.commit()
203 self.sa.commit()
201 except:
204 except:
202 self.sa.rollback()
205 self.sa.rollback()
@@ -13,6 +13,14 b' class RhodeCodeSettings(Base):'
13 app_settings_name = Column("app_settings_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
13 app_settings_name = Column("app_settings_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
14 app_settings_value = Column("app_settings_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
14 app_settings_value = Column("app_settings_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
15
15
16 def __init__(self, k, v):
17 self.app_settings_name = k
18 self.app_settings_value = v
19
20 def __repr__(self):
21 return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name,
22 self.app_settings_value)
23
16 class RhodeCodeUi(Base):
24 class RhodeCodeUi(Base):
17 __tablename__ = 'rhodecode_ui'
25 __tablename__ = 'rhodecode_ui'
18 __table_args__ = {'useexisting':True}
26 __table_args__ = {'useexisting':True}
@@ -35,9 +43,10 b' class User(Base):'
35 lastname = Column("lastname", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
43 lastname = Column("lastname", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
36 email = Column("email", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
44 email = Column("email", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
37 last_login = Column("last_login", DATETIME(timezone=False), nullable=True, unique=None, default=None)
45 last_login = Column("last_login", DATETIME(timezone=False), nullable=True, unique=None, default=None)
46 is_ldap = Column("is_ldap", BOOLEAN(), nullable=False, unique=None, default=False)
38
47
39 user_log = relation('UserLog')
48 user_log = relation('UserLog', cascade='all')
40 user_perms = relation('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id")
49 user_perms = relation('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
41
50
42 @LazyProperty
51 @LazyProperty
43 def full_contact(self):
52 def full_contact(self):
General Comments 0
You need to be logged in to leave comments. Login now