Mercurial > kallithea
comparison rhodecode/model/__init__.py @ 759:a7f50911a945 beta
Models code cleanups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 25 Nov 2010 22:16:29 +0100 |
parents | 89b9037d68b7 |
children | bb35ad076e2f |
comparison
equal
deleted
inserted
replaced
758:6a31e64acabd | 759:a7f50911a945 |
---|---|
1 """The application's model objects""" | 1 # -*- coding: utf-8 -*- |
2 """ | |
3 package.rhodecode.model.__init__ | |
4 ~~~~~~~~~~~~~~ | |
5 The application's model objects | |
6 | |
7 :created_on: Nov 25, 2010 | |
8 :author: marcink | |
9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
10 :license: GPLv3, see COPYING for more details. | |
11 | |
12 | |
13 :example: | |
14 from paste.deploy import appconfig | |
15 from pylons import config | |
16 from sqlalchemy import engine_from_config | |
17 from rhodecode.config.environment import load_environment | |
18 | |
19 conf = appconfig('config:development.ini', relative_to = './../../') | |
20 load_environment(conf.global_conf, conf.local_conf) | |
21 | |
22 engine = engine_from_config(config, 'sqlalchemy.') | |
23 init_model(engine) | |
24 #RUN YOUR CODE HERE | |
25 | |
26 """ | |
27 # This program is free software; you can redistribute it and/or | |
28 # modify it under the terms of the GNU General Public License | |
29 # as published by the Free Software Foundation; version 2 | |
30 # of the License or (at your opinion) any later version of the license. | |
31 # | |
32 # This program is distributed in the hope that it will be useful, | |
33 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35 # GNU General Public License for more details. | |
36 # | |
37 # You should have received a copy of the GNU General Public License | |
38 # along with this program; if not, write to the Free Software | |
39 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
40 # MA 02110-1301, USA. | |
41 | |
2 import logging | 42 import logging |
3 from rhodecode.model import meta | 43 from rhodecode.model import meta |
4 log = logging.getLogger(__name__) | 44 log = logging.getLogger(__name__) |
5 | 45 |
6 def init_model(engine): | 46 def init_model(engine): |
7 """Call me before using any of the tables or classes in the model""" | 47 """Call me before using any of the tables or classes in the model""" |
8 log.info("INITIALIZING DB MODELS") | 48 log.info("initializing db models for %s", engine) |
9 meta.Base.metadata.bind = engine | 49 meta.Base.metadata.bind = engine |
10 #meta.Base2.metadata.bind = engine2 | |
11 | |
12 #THIS IS A TEST FOR EXECUTING SCRIPT AND LOAD PYLONS APPLICATION GLOBALS | |
13 #from paste.deploy import appconfig | |
14 #from pylons import config | |
15 #from sqlalchemy import engine_from_config | |
16 #from rhodecode.config.environment import load_environment | |
17 # | |
18 #conf = appconfig('config:development.ini', relative_to = './../../') | |
19 #load_environment(conf.global_conf, conf.local_conf) | |
20 # | |
21 #engine = engine_from_config(config, 'sqlalchemy.') | |
22 #init_model(engine) | |
23 # DO SOMETHING | |
24 | |
25 | 50 |
26 class BaseModel(object): | 51 class BaseModel(object): |
27 | 52 |
28 def __init__(self, sa=None): | 53 def __init__(self, sa=None): |
29 if sa is not None: | 54 if sa is not None: |