comparison rhodecode/model/__init__.py @ 811:bb35ad076e2f beta

docs updates
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 05 Dec 2010 17:22:57 +0100
parents a7f50911a945
children 07a6e8c65526 a3b2b4b4e440
comparison
equal deleted inserted replaced
810:bd57d1cb9dc3 811:bb35ad076e2f
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 """ 2 """
3 package.rhodecode.model.__init__ 3 rhodecode.model.__init__
4 ~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
5 The application's model objects 6 The application's model objects
6 7
7 :created_on: Nov 25, 2010 8 :created_on: Nov 25, 2010
8 :author: marcink 9 :author: marcink
9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> 10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 :license: GPLv3, see COPYING for more details. 11 :license: GPLv3, see COPYING for more details.
11 12
12 13
13 :example: 14 :example:
14 from paste.deploy import appconfig 15
15 from pylons import config 16 .. code-block:: python
16 from sqlalchemy import engine_from_config 17
17 from rhodecode.config.environment import load_environment 18 from paste.deploy import appconfig
18 19 from pylons import config
19 conf = appconfig('config:development.ini', relative_to = './../../') 20 from sqlalchemy import engine_from_config
20 load_environment(conf.global_conf, conf.local_conf) 21 from rhodecode.config.environment import load_environment
21 22
22 engine = engine_from_config(config, 'sqlalchemy.') 23 conf = appconfig('config:development.ini', relative_to = './../../')
23 init_model(engine) 24 load_environment(conf.global_conf, conf.local_conf)
24 #RUN YOUR CODE HERE 25
26 engine = engine_from_config(config, 'sqlalchemy.')
27 init_model(engine)
28 # RUN YOUR CODE HERE
25 29
26 """ 30 """
27 # This program is free software; you can redistribute it and/or 31 # This program is free software; you can redistribute it and/or
28 # modify it under the terms of the GNU General Public License 32 # modify it under the terms of the GNU General Public License
29 # as published by the Free Software Foundation; version 2 33 # as published by the Free Software Foundation; version 2
42 import logging 46 import logging
43 from rhodecode.model import meta 47 from rhodecode.model import meta
44 log = logging.getLogger(__name__) 48 log = logging.getLogger(__name__)
45 49
46 def init_model(engine): 50 def init_model(engine):
47 """Call me before using any of the tables or classes in the model""" 51 """Initializes db session, bind the engine with the metadata,
52 Call this before using any of the tables or classes in the model, preferably
53 once in application start
54
55 :param engine: engine to bind to
56 """
48 log.info("initializing db models for %s", engine) 57 log.info("initializing db models for %s", engine)
49 meta.Base.metadata.bind = engine 58 meta.Base.metadata.bind = engine
50 59
51 class BaseModel(object): 60 class BaseModel(object):
61 """Base Model for all RhodeCode models, it adds sql alchemy session
62 into instance of model
63
64 :param sa: If passed it reuses this session instead of creating a new one
65 """
52 66
53 def __init__(self, sa=None): 67 def __init__(self, sa=None):
54 if sa is not None: 68 if sa is not None:
55 self.sa = sa 69 self.sa = sa
56 else: 70 else: