Show More
@@ -1,27 +1,52 b'' | |||||
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 |
@@ -1,9 +1,38 b'' | |||||
1 | from rhodecode.model.meta import Base |
|
1 | # -*- coding: utf-8 -*- | |
|
2 | """ | |||
|
3 | package.rhodecode.model.db | |||
|
4 | ~~~~~~~~~~~~~~ | |||
|
5 | ||||
|
6 | Database Models for RhodeCode | |||
|
7 | :created_on: Apr 08, 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 | # This program is free software; you can redistribute it and/or | |||
|
13 | # modify it under the terms of the GNU General Public License | |||
|
14 | # as published by the Free Software Foundation; version 2 | |||
|
15 | # of the License or (at your opinion) any later version of the license. | |||
|
16 | # | |||
|
17 | # This program is distributed in the hope that it will be useful, | |||
|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
20 | # GNU General Public License for more details. | |||
|
21 | # | |||
|
22 | # You should have received a copy of the GNU General Public License | |||
|
23 | # along with this program; if not, write to the Free Software | |||
|
24 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |||
|
25 | # MA 02110-1301, USA. | |||
|
26 | import logging | |||
|
27 | import datetime | |||
|
28 | ||||
2 | from sqlalchemy import * |
|
29 | from sqlalchemy import * | |
|
30 | from sqlalchemy.exc import DatabaseError | |||
3 | from sqlalchemy.orm import relation, backref |
|
31 | from sqlalchemy.orm import relation, backref | |
4 | from sqlalchemy.orm.session import Session |
|
32 | from sqlalchemy.orm.session import Session | |
5 | from vcs.utils.lazy import LazyProperty |
|
33 | ||
6 | import logging |
|
34 | from rhodecode.model.meta import Base | |
|
35 | ||||
7 | log = logging.getLogger(__name__) |
|
36 | log = logging.getLogger(__name__) | |
8 |
|
37 | |||
9 | class RhodeCodeSettings(Base): |
|
38 | class RhodeCodeSettings(Base): | |
@@ -51,7 +80,7 b' class User(Base):' | |||||
51 | repositories = relation('Repository') |
|
80 | repositories = relation('Repository') | |
52 | user_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') |
|
81 | user_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') | |
53 |
|
82 | |||
54 |
@ |
|
83 | @property | |
55 | def full_contact(self): |
|
84 | def full_contact(self): | |
56 | return '%s %s <%s>' % (self.name, self.lastname, self.email) |
|
85 | return '%s %s <%s>' % (self.name, self.lastname, self.email) | |
57 |
|
86 | |||
@@ -60,7 +89,6 b' class User(Base):' | |||||
60 |
|
89 | |||
61 | def update_lastlogin(self): |
|
90 | def update_lastlogin(self): | |
62 | """Update user lastlogin""" |
|
91 | """Update user lastlogin""" | |
63 | import datetime |
|
|||
64 |
|
92 | |||
65 | try: |
|
93 | try: | |
66 | session = Session.object_session(self) |
|
94 | session = Session.object_session(self) | |
@@ -68,7 +96,7 b' class User(Base):' | |||||
68 | session.add(self) |
|
96 | session.add(self) | |
69 | session.commit() |
|
97 | session.commit() | |
70 | log.debug('updated user %s lastlogin', self.username) |
|
98 | log.debug('updated user %s lastlogin', self.username) | |
71 |
except |
|
99 | except (DatabaseError,): | |
72 | session.rollback() |
|
100 | session.rollback() | |
73 |
|
101 | |||
74 |
|
102 |
@@ -1,8 +1,14 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | # -*- coding: utf-8 -*- | |
2 | # encoding: utf-8 |
|
2 | """ | |
3 | # Model for permissions |
|
3 | package.rhodecode.model.permission | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | ~~~~~~~~~~~~~~ | |
5 |
|
|
5 | ||
|
6 | permissions model for RhodeCode | |||
|
7 | :created_on: Aug 20, 2010 | |||
|
8 | :author: marcink | |||
|
9 | :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |||
|
10 | :license: GPLv3, see COPYING for more details. | |||
|
11 | """ | |||
6 | # This program is free software; you can redistribute it and/or |
|
12 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
13 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; version 2 |
|
14 | # as published by the Free Software Foundation; version 2 | |
@@ -17,17 +23,16 b'' | |||||
17 | # along with this program; if not, write to the Free Software |
|
23 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
24 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. |
|
25 | # MA 02110-1301, USA. | |
20 | """ |
|
26 | ||
21 | Created on Aug 20, 2010 |
|
27 | import logging | |
22 | Model for permissions |
|
28 | import traceback | |
23 | :author: marcink |
|
29 | ||
24 | """ |
|
30 | from sqlalchemy.exc import DatabaseError | |
25 |
|
31 | |||
26 | from rhodecode.model import BaseModel |
|
32 | from rhodecode.model import BaseModel | |
27 | from rhodecode.model.db import User, Permission, UserToPerm, RepoToPerm |
|
33 | from rhodecode.model.db import User, Permission, UserToPerm, RepoToPerm | |
28 | from rhodecode.model.caching_query import FromCache |
|
34 | from rhodecode.model.caching_query import FromCache | |
29 | import logging |
|
35 | ||
30 | import traceback |
|
|||
31 | log = logging.getLogger(__name__) |
|
36 | log = logging.getLogger(__name__) | |
32 |
|
37 | |||
33 |
|
38 | |||
@@ -90,7 +95,7 b' class PermissionModel(BaseModel):' | |||||
90 |
|
95 | |||
91 |
|
96 | |||
92 | self.sa.commit() |
|
97 | self.sa.commit() | |
93 | except: |
|
98 | except (DatabaseError,): | |
94 | log.error(traceback.format_exc()) |
|
99 | log.error(traceback.format_exc()) | |
95 | self.sa.rollback() |
|
100 | self.sa.rollback() | |
96 | raise |
|
101 | raise |
General Comments 0
You need to be logged in to leave comments.
Login now