comparison rhodecode/model/__init__.py @ 1203:6832ef664673 beta

source code cleanup: remove trailing white space, normalize file endings
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 03 Apr 2011 18:23:15 +0200
parents 37a9421f32a0
children a671db5bdd58
comparison
equal deleted inserted replaced
1202:eef9e273347a 1203:6832ef664673
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 """ 2 """
3 rhodecode.model.__init__ 3 rhodecode.model.__init__
4 ~~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 The application's model objects 6 The application's model objects
7 7
8 :created_on: Nov 25, 2010 8 :created_on: Nov 25, 2010
9 :author: marcink 9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> 10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details. 11 :license: GPLv3, see COPYING for more details.
12 12
13 13
14 :example: 14 :example:
15 15
16 .. code-block:: python 16 .. code-block:: python
17 17
18 from paste.deploy import appconfig 18 from paste.deploy import appconfig
19 from pylons import config 19 from pylons import config
20 from sqlalchemy import engine_from_config 20 from sqlalchemy import engine_from_config
21 from rhodecode.config.environment import load_environment 21 from rhodecode.config.environment import load_environment
22 22
23 conf = appconfig('config:development.ini', relative_to = './../../') 23 conf = appconfig('config:development.ini', relative_to = './../../')
24 load_environment(conf.global_conf, conf.local_conf) 24 load_environment(conf.global_conf, conf.local_conf)
25 25
26 engine = engine_from_config(config, 'sqlalchemy.') 26 engine = engine_from_config(config, 'sqlalchemy.')
27 init_model(engine) 27 init_model(engine)
28 # RUN YOUR CODE HERE 28 # RUN YOUR CODE HERE
29 29
30 """ 30 """
31 # This program is free software; you can redistribute it and/or 31 # This program is free software; you can redistribute it and/or
32 # modify it under the terms of the GNU General Public License 32 # modify it under the terms of the GNU General Public License
33 # as published by the Free Software Foundation; version 2 33 # as published by the Free Software Foundation; version 2
34 # of the License or (at your opinion) any later version of the license. 34 # of the License or (at your opinion) any later version of the license.
35 # 35 #
36 # This program is distributed in the hope that it will be useful, 36 # This program is distributed in the hope that it will be useful,
37 # but WITHOUT ANY WARRANTY; without even the implied warranty of 37 # but WITHOUT ANY WARRANTY; without even the implied warranty of
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 # GNU General Public License for more details. 39 # GNU General Public License for more details.
40 # 40 #
41 # You should have received a copy of the GNU General Public License 41 # You should have received a copy of the GNU General Public License
42 # along with this program; if not, write to the Free Software 42 # along with this program; if not, write to the Free Software
43 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 43 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
44 # MA 02110-1301, USA. 44 # MA 02110-1301, USA.
45 45
51 51
52 def init_model(engine): 52 def init_model(engine):
53 """Initializes db session, bind the engine with the metadata, 53 """Initializes db session, bind the engine with the metadata,
54 Call this before using any of the tables or classes in the model, preferably 54 Call this before using any of the tables or classes in the model, preferably
55 once in application start 55 once in application start
56 56
57 :param engine: engine to bind to 57 :param engine: engine to bind to
58 """ 58 """
59 log.info("initializing db for %s", engine) 59 log.info("initializing db for %s", engine)
60 meta.Base.metadata.bind = engine 60 meta.Base.metadata.bind = engine
61 61
62 class BaseModel(object): 62 class BaseModel(object):
63 """Base Model for all RhodeCode models, it adds sql alchemy session 63 """Base Model for all RhodeCode models, it adds sql alchemy session
64 into instance of model 64 into instance of model
65 65
66 :param sa: If passed it reuses this session instead of creating a new one 66 :param sa: If passed it reuses this session instead of creating a new one
67 """ 67 """
68 68
69 def __init__(self, sa=None): 69 def __init__(self, sa=None):
70 if sa is not None: 70 if sa is not None: