annotate rhodecode/model/db.py @ 972:2c8fd84935a4 beta

#56 implemented users groups editing, fixed sqlalchemy relation function into relationship (according to 0.6)
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 28 Jan 2011 18:40:50 +0100
parents 72f008ed9b18
children f6658c70eeeb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
1 # -*- coding: utf-8 -*-
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
2 """
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
3 rhodecode.model.db
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
4 ~~~~~~~~~~~~~~~~~~
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
5
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
6 Database Models for RhodeCode
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
7
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
8 :created_on: Apr 08, 2010
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
9 :author: marcink
902
07a6e8c65526 fixed copyright year to 2011
Marcin Kuzminski <marcin@python-works.com>
parents: 895
diff changeset
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
11 :license: GPLv3, see COPYING for more details.
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
12 """
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
13 # This program is free software; you can redistribute it and/or
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
14 # modify it under the terms of the GNU General Public License
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
15 # as published by the Free Software Foundation; version 2
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
16 # of the License or (at your opinion) any later version of the license.
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
17 #
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
18 # This program is distributed in the hope that it will be useful,
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
21 # GNU General Public License for more details.
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
22 #
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
23 # You should have received a copy of the GNU General Public License
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
24 # along with this program; if not, write to the Free Software
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
26 # MA 02110-1301, USA.
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
27 import logging
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
28 import datetime
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
29
658
4ecb2ffcc110 fixed imports
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
30 from sqlalchemy import *
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
31 from sqlalchemy.exc import DatabaseError
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
32 from sqlalchemy.orm import relationship, backref, class_mapper
658
4ecb2ffcc110 fixed imports
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
33 from sqlalchemy.orm.session import Session
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
34
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
35 from rhodecode.model.meta import Base
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
36
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
37 log = logging.getLogger(__name__)
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
38
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
39 class BaseModel(object):
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
40
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
41 @classmethod
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
42 def _get_keys(cls):
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
43 """return column names for this model """
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
44 return class_mapper(cls).c.keys()
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
45
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
46 def get_dict(self):
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
47 """return dict with keys and values corresponding
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
48 to this model data """
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
49
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
50 d = {}
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
51 for k in self._get_keys():
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
52 d[k] = getattr(self, k)
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
53 return d
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
54
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
55 def get_appstruct(self):
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
56 """return list with keys and values tupples corresponding
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
57 to this model data """
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
58
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
59 l = []
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
60 for k in self._get_keys():
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
61 l.append((k, getattr(self, k),))
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
62 return l
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
63
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
64 def populate_obj(self, populate_dict):
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
65 """populate model with data from given populate_dict"""
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
66
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
67 for k in self._get_keys():
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
68 if k in populate_dict:
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
69 setattr(self, k, populate_dict[k])
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
70
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
71 class RhodeCodeSettings(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
72 __tablename__ = 'rhodecode_settings'
381
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
73 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
74 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
75 app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
76 app_settings_value = Column("app_settings_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 328
diff changeset
77
907
2f83756f3041 Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
78 def __init__(self, k='', v=''):
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
79 self.app_settings_name = k
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
80 self.app_settings_value = v
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
81
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
82 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
83 return "<%s('%s:%s')>" % (self.__class__.__name__,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
84 self.app_settings_name, self.app_settings_value)
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
85
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
86 class RhodeCodeUi(Base, BaseModel):
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
87 __tablename__ = 'rhodecode_ui'
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 328
diff changeset
88 __table_args__ = {'useexisting':True}
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
89 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
90 ui_section = Column("ui_section", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
91 ui_key = Column("ui_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
92 ui_value = Column("ui_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
93 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
94
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
95
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
96 class User(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
97 __tablename__ = 'users'
473
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
98 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
99 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
100 username = Column("username", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
101 password = Column("password", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
102 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
103 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
104 name = Column("name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
105 lastname = Column("lastname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
106 email = Column("email", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
107 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
108 is_ldap = Column("is_ldap", Boolean(), nullable=False, unique=None, default=False)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
109
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
110 user_log = relationship('UserLog', cascade='all')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
111 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
112
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
113 repositories = relationship('Repository')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
114 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
713
1bb0fcdec895 fixed #72 show warning on removal when user still is owner of existing repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
115
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
116 @property
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
117 def full_contact(self):
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
118 return '%s %s <%s>' % (self.name, self.lastname, self.email)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
119
895
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
120
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
121 @property
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
122 def is_admin(self):
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
123 return self.admin
62c04c5cc971 Added some more details into user edit permissions view
Marcin Kuzminski <marcin@python-works.com>
parents: 880
diff changeset
124
232
37a832dc4a82 some beaker cache changes, and added repr to models
Marcin Kuzminski <marcin@python-works.com>
parents: 226
diff changeset
125 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
126 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
127 self.user_id, self.username)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
128
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
129 def update_lastlogin(self):
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
130 """Update user lastlogin"""
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
131
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
132 try:
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
133 session = Session.object_session(self)
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
134 self.last_login = datetime.datetime.now()
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
135 session.add(self)
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
136 session.commit()
473
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 462
diff changeset
137 log.debug('updated user %s lastlogin', self.username)
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
138 except (DatabaseError,):
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
139 session.rollback()
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
140
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
141
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
142 class UserLog(Base, BaseModel):
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
143 __tablename__ = 'user_logs'
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
144 __table_args__ = {'useexisting':True}
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
145 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
146 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
147 repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
148 repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
149 user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
150 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
151 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
152
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
153 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
154 repository = relationship('Repository')
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
155
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
156
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
157 class UsersGroup(Base, BaseModel):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
158 __tablename__ = 'users_groups'
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
159 __table_args__ = {'useexisting':True}
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
160
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
161 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
162 users_group_name = Column("users_group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
163 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
164
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
165 members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan")
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
166
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
167 class UsersGroupMember(Base, BaseModel):
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
168 __tablename__ = 'users_groups_members'
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
169 __table_args__ = {'useexisting':True}
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
170
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
171 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
172 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
173 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
174
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
175 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
176 users_group = relationship('UsersGroup')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
177
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
178 def __init__(self, gr_id, u_id):
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
179 self.users_group_id = gr_id
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
180 self.user_id = u_id
956
83d35d716a02 started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
181
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
182 class Repository(Base, BaseModel):
234
a0116e944da1 changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents: 232
diff changeset
183 __tablename__ = 'repositories'
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
184 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
185 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
186 repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
836
28a4bb11bb6f dbmigrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
187 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
188 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
189 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
810
bd57d1cb9dc3 fixes #62, added option to disable statistics for each repository
Marcin Kuzminski <marcin@python-works.com>
parents: 780
diff changeset
190 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
962
72f008ed9b18 implemented #84 downloads can be enabled/disabled per each repository from now.
Marcin Kuzminski <marcin@python-works.com>
parents: 959
diff changeset
191 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
192 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
193 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
194 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
195
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
196 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
197 fork = relationship('Repository', remote_side=repo_id)
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
198 group = relationship('Group')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
199 repo_to_perm = relationship('RepoToPerm', cascade='all')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
200 stats = relationship('Statistics', cascade='all', uselist=False)
667
56a8434a88cc fixes #51 deleting a repo didn't delete it's dependent db entries.
Marcin Kuzminski <marcin@python-works.com>
parents: 658
diff changeset
201
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
202 repo_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
203
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 414
diff changeset
204 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
205 return "<%s('%s:%s')>" % (self.__class__.__name__,
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
206 self.repo_id, self.repo_name)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
207
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
208 class Group(Base, BaseModel):
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
209 __tablename__ = 'groups'
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
210 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
211
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
212 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
213 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
214 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
215
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
216 parent_group = relationship('Group', remote_side=group_id)
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
217
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
218
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
219 def __init__(self, group_name='', parent_group=None):
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
220 self.group_name = group_name
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
221 self.parent_group = parent_group
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
222
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
223 def __repr__(self):
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
224 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
225 self.group_name)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
226
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
227 class Permission(Base, BaseModel):
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 89
diff changeset
228 __tablename__ = 'permissions'
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 89
diff changeset
229 __table_args__ = {'useexisting':True}
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
230 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
231 permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
232 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
233
232
37a832dc4a82 some beaker cache changes, and added repr to models
Marcin Kuzminski <marcin@python-works.com>
parents: 226
diff changeset
234 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
235 return "<%s('%s:%s')>" % (self.__class__.__name__,
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
236 self.permission_id, self.permission_name)
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
237
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
238 class RepoToPerm(Base, BaseModel):
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
239 __tablename__ = 'repo_to_perm'
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
240 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
241 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
242 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
243 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
244 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
245
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
246 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
247 permission = relationship('Permission')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
248 repository = relationship('Repository')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
249
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
250 class UserToPerm(Base, BaseModel):
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
251 __tablename__ = 'user_to_perm'
414
27f801e03489 fixed escaping for new webhelpers and added perm2user constraint
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
252 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
253 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
254 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
255 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
256
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
257 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
258 permission = relationship('Permission')
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
259
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
260 class UsersGroupToPerm(Base, BaseModel):
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
261 __tablename__ = 'users_group_to_perm'
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
262 __table_args__ = (UniqueConstraint('users_group_id', 'permission_id'), {'useexisting':True})
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
263 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
959
fff21c9b075c #56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents: 958
diff changeset
264 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
265 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
266
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
267 users_group = relationship('UsersGroup')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
268 permission = relationship('Permission')
958
7d1483f3170b added user group to perm table
Marcin Kuzminski <marcin@python-works.com>
parents: 956
diff changeset
269
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
270 class GroupToPerm(Base, BaseModel):
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
271 __tablename__ = 'group_to_perm'
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
272 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
273
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
274 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
275 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
276 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
277 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
278
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
279 user = relationship('User')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
280 permission = relationship('Permission')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
281 group = relationship('Group')
879
b19341623d48 added group to perm mapping table
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
282
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
283 class Statistics(Base, BaseModel):
493
2256c78afe53 implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
284 __tablename__ = 'statistics'
2256c78afe53 implemented basic autoupdating statistics fetched from database
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
285 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
286 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
287 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
288 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
289 commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
290 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
291 languages = Column("languages", LargeBinary(), nullable=False)#JSON data
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
292
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
293 repository = relationship('Repository', single_parent=True)
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
294
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
295 class UserFollowing(Base, BaseModel):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
296 __tablename__ = 'user_followings'
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
297 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
298 UniqueConstraint('user_id', 'follows_user_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
299 , {'useexisting':True})
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
300
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
301 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
880
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
302 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
303 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
014071a745da removed unicode from models string params
Marcin Kuzminski <marcin@python-works.com>
parents: 879
diff changeset
304 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
305
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
306 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
307
972
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
308 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
2c8fd84935a4 #56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents: 962
diff changeset
309 follows_repository = relationship('Repository')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 713
diff changeset
310
832
634596f81cfd new improved models with helper functions for easier data fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 810
diff changeset
311 class CacheInvalidation(Base, BaseModel):
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
312 __tablename__ = 'cache_invalidation'
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
313 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
780
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
314 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
315 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
316 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92fa9c3414d0 fixed models for compatibility with database systems
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
317 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
670
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
318
e7c670cc03cb Adde table for cache invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 667
diff changeset
319
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
320 def __init__(self, cache_key, cache_args=''):
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
321 self.cache_key = cache_key
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
322 self.cache_args = cache_args
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
323 self.cache_active = False
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
324
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 670
diff changeset
325 def __repr__(self):
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
326 return "<%s('%s:%s')>" % (self.__class__.__name__,
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 836
diff changeset
327 self.cache_id, self.cache_key)
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
328
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
329 class DbMigrateVersion(Base, BaseModel):
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
330 __tablename__ = 'db_migrate_version'
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
331 __table_args__ = {'useexisting':True}
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
332 repository_id = Column('repository_id', String(250), primary_key=True)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
333 repository_path = Column('repository_path', Text)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
334 version = Column('version', Integer)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 832
diff changeset
335