Mercurial > kallithea
annotate rhodecode/model/__init__.py @ 1217:a3b2b4b4e440
fixes for issue #149
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 05 Apr 2011 18:04:06 +0200 |
parents | bb35ad076e2f |
children | bf263968da47 |
rev | line source |
---|---|
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
2 """ |
811 | 3 rhodecode.model.__init__ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
6 The application's model objects |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
7 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
8 :created_on: Nov 25, 2010 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
9 :author: marcink |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
12 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
13 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
14 :example: |
811 | 15 |
16 .. code-block:: python | |
17 | |
18 from paste.deploy import appconfig | |
19 from pylons import config | |
20 from sqlalchemy import engine_from_config | |
21 from rhodecode.config.environment import load_environment | |
22 | |
23 conf = appconfig('config:development.ini', relative_to = './../../') | |
24 load_environment(conf.global_conf, conf.local_conf) | |
25 | |
26 engine = engine_from_config(config, 'sqlalchemy.') | |
27 init_model(engine) | |
28 # RUN YOUR CODE HERE | |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
29 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
30 """ |
1217
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
31 # This program is free software: you can redistribute it and/or modify |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
32 # it under the terms of the GNU General Public License as published by |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
33 # the Free Software Foundation, either version 3 of the License, or |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
34 # (at your option) any later version. |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
35 # |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
36 # This program is distributed in the hope that it will be useful, |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
37 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
39 # GNU General Public License for more details. |
1217
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
40 # |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
41 # You should have received a copy of the GNU General Public License |
1217
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
42 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
43 |
0 | 44 import logging |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
45 from rhodecode.model import meta |
0 | 46 log = logging.getLogger(__name__) |
47 | |
48 def init_model(engine): | |
811 | 49 """Initializes db session, bind the engine with the metadata, |
50 Call this before using any of the tables or classes in the model, preferably | |
51 once in application start | |
52 | |
53 :param engine: engine to bind to | |
54 """ | |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
55 log.info("initializing db models for %s", engine) |
0 | 56 meta.Base.metadata.bind = engine |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
57 |
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
58 class BaseModel(object): |
811 | 59 """Base Model for all RhodeCode models, it adds sql alchemy session |
60 into instance of model | |
61 | |
62 :param sa: If passed it reuses this session instead of creating a new one | |
63 """ | |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
64 |
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
65 def __init__(self, sa=None): |
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
66 if sa is not None: |
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
67 self.sa = sa |
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
68 else: |
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
69 self.sa = meta.Session() |