Show More
@@ -291,7 +291,7 b' class ReposController(BaseController):' | |||
|
291 | 291 | c.stats_percentage = '%.2f' % ((float((last_rev)) / |
|
292 | 292 | c.repo_last_rev) * 100) |
|
293 | 293 | |
|
294 |
defaults = c.repo_info. |
|
|
294 | defaults = c.repo_info.get_dict() | |
|
295 | 295 | if c.repo_info.user: |
|
296 | 296 | defaults.update({'user':c.repo_info.user.username}) |
|
297 | 297 | else: |
@@ -258,7 +258,7 b' class SettingsController(BaseController)' | |||
|
258 | 258 | " crucial for entire application"), category='warning') |
|
259 | 259 | return redirect(url('users')) |
|
260 | 260 | |
|
261 |
defaults = c.user. |
|
|
261 | defaults = c.user.get_dict() | |
|
262 | 262 | return htmlfill.render( |
|
263 | 263 | render('admin/users/user_edit_my_account.html'), |
|
264 | 264 | defaults=defaults, |
@@ -158,7 +158,7 b' class UsersController(BaseController):' | |||
|
158 | 158 | h.flash(_("You can't edit this user"), category='warning') |
|
159 | 159 | return redirect(url('users')) |
|
160 | 160 | |
|
161 |
defaults = c.user. |
|
|
161 | defaults = c.user.get_dict() | |
|
162 | 162 | return htmlfill.render( |
|
163 | 163 | render('admin/users/user_edit.html'), |
|
164 | 164 | defaults=defaults, |
@@ -56,7 +56,7 b' class SettingsController(BaseController)' | |||
|
56 | 56 | category='error') |
|
57 | 57 | |
|
58 | 58 | return redirect(url('home')) |
|
59 |
defaults = c.repo_info. |
|
|
59 | defaults = c.repo_info.get_dict() | |
|
60 | 60 | defaults.update({'user':c.repo_info.user.username}) |
|
61 | 61 | c.users_array = repo_model.get_users_js() |
|
62 | 62 |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 |
|
|
|
4 | ~~~~~~~~~~~~~~ | |
|
3 | rhodecode.model.db | |
|
4 | ~~~~~~~~~~~~~~~~~~ | |
|
5 | 5 | |
|
6 | 6 | Database Models for RhodeCode |
|
7 | 7 | :created_on: Apr 08, 2010 |
@@ -28,14 +28,46 b' import datetime' | |||
|
28 | 28 | |
|
29 | 29 | from sqlalchemy import * |
|
30 | 30 | from sqlalchemy.exc import DatabaseError |
|
31 | from sqlalchemy.orm import relation, backref | |
|
31 | from sqlalchemy.orm import relation, backref, class_mapper | |
|
32 | 32 | from sqlalchemy.orm.session import Session |
|
33 | 33 | |
|
34 | 34 | from rhodecode.model.meta import Base |
|
35 | 35 | |
|
36 | 36 | log = logging.getLogger(__name__) |
|
37 | 37 | |
|
38 | class RhodeCodeSettings(Base): | |
|
38 | class BaseModel(object): | |
|
39 | ||
|
40 | @classmethod | |
|
41 | def _get_keys(cls): | |
|
42 | """return column names for this model """ | |
|
43 | return class_mapper(cls).c.keys() | |
|
44 | ||
|
45 | def get_dict(self): | |
|
46 | """return dict with keys and values corresponding | |
|
47 | to this model data """ | |
|
48 | ||
|
49 | d = {} | |
|
50 | for k in self._get_keys(): | |
|
51 | d[k] = getattr(self, k) | |
|
52 | return d | |
|
53 | ||
|
54 | def get_appstruct(self): | |
|
55 | """return list with keys and values tupples corresponding | |
|
56 | to this model data """ | |
|
57 | ||
|
58 | l = [] | |
|
59 | for k in self._get_keys(): | |
|
60 | l.append((k, getattr(self, k),)) | |
|
61 | return l | |
|
62 | ||
|
63 | def populate_obj(self, populate_dict): | |
|
64 | """populate model with data from given populate_dict""" | |
|
65 | ||
|
66 | for k in self._get_keys(): | |
|
67 | if k in populate_dict: | |
|
68 | setattr(self, k, populate_dict[k]) | |
|
69 | ||
|
70 | class RhodeCodeSettings(Base, BaseModel): | |
|
39 | 71 | __tablename__ = 'rhodecode_settings' |
|
40 | 72 | __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True}) |
|
41 | 73 | app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -50,7 +82,7 b' class RhodeCodeSettings(Base):' | |||
|
50 | 82 | return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name, |
|
51 | 83 | self.app_settings_value) |
|
52 | 84 | |
|
53 | class RhodeCodeUi(Base): | |
|
85 | class RhodeCodeUi(Base, BaseModel): | |
|
54 | 86 | __tablename__ = 'rhodecode_ui' |
|
55 | 87 | __table_args__ = {'useexisting':True} |
|
56 | 88 | ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -60,7 +92,7 b' class RhodeCodeUi(Base):' | |||
|
60 | 92 | ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) |
|
61 | 93 | |
|
62 | 94 | |
|
63 | class User(Base): | |
|
95 | class User(Base, BaseModel): | |
|
64 | 96 | __tablename__ = 'users' |
|
65 | 97 | __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True}) |
|
66 | 98 | user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -100,7 +132,7 b' class User(Base):' | |||
|
100 | 132 | session.rollback() |
|
101 | 133 | |
|
102 | 134 | |
|
103 | class UserLog(Base): | |
|
135 | class UserLog(Base, BaseModel): | |
|
104 | 136 | __tablename__ = 'user_logs' |
|
105 | 137 | __table_args__ = {'useexisting':True} |
|
106 | 138 | user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -114,7 +146,7 b' class UserLog(Base):' | |||
|
114 | 146 | user = relation('User') |
|
115 | 147 | repository = relation('Repository') |
|
116 | 148 | |
|
117 | class Repository(Base): | |
|
149 | class Repository(Base, BaseModel): | |
|
118 | 150 | __tablename__ = 'repositories' |
|
119 | 151 | __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},) |
|
120 | 152 | repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -137,7 +169,7 b' class Repository(Base):' | |||
|
137 | 169 | def __repr__(self): |
|
138 | 170 | return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name) |
|
139 | 171 | |
|
140 | class Permission(Base): | |
|
172 | class Permission(Base, BaseModel): | |
|
141 | 173 | __tablename__ = 'permissions' |
|
142 | 174 | __table_args__ = {'useexisting':True} |
|
143 | 175 | permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -147,7 +179,7 b' class Permission(Base):' | |||
|
147 | 179 | def __repr__(self): |
|
148 | 180 | return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name) |
|
149 | 181 | |
|
150 | class RepoToPerm(Base): | |
|
182 | class RepoToPerm(Base, BaseModel): | |
|
151 | 183 | __tablename__ = 'repo_to_perm' |
|
152 | 184 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) |
|
153 | 185 | repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -159,7 +191,7 b' class RepoToPerm(Base):' | |||
|
159 | 191 | permission = relation('Permission') |
|
160 | 192 | repository = relation('Repository') |
|
161 | 193 | |
|
162 | class UserToPerm(Base): | |
|
194 | class UserToPerm(Base, BaseModel): | |
|
163 | 195 | __tablename__ = 'user_to_perm' |
|
164 | 196 | __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True}) |
|
165 | 197 | user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -169,7 +201,7 b' class UserToPerm(Base):' | |||
|
169 | 201 | user = relation('User') |
|
170 | 202 | permission = relation('Permission') |
|
171 | 203 | |
|
172 | class Statistics(Base): | |
|
204 | class Statistics(Base, BaseModel): | |
|
173 | 205 | __tablename__ = 'statistics' |
|
174 | 206 | __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True}) |
|
175 | 207 | stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -181,7 +213,7 b' class Statistics(Base):' | |||
|
181 | 213 | |
|
182 | 214 | repository = relation('Repository', single_parent=True) |
|
183 | 215 | |
|
184 | class UserFollowing(Base): | |
|
216 | class UserFollowing(Base, BaseModel): | |
|
185 | 217 | __tablename__ = 'user_followings' |
|
186 | 218 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), |
|
187 | 219 | UniqueConstraint('user_id', 'follows_user_id') |
@@ -198,7 +230,7 b' class UserFollowing(Base):' | |||
|
198 | 230 | follows_repository = relation('Repository') |
|
199 | 231 | |
|
200 | 232 | |
|
201 | class CacheInvalidation(Base): | |
|
233 | class CacheInvalidation(Base, BaseModel): | |
|
202 | 234 | __tablename__ = 'cache_invalidation' |
|
203 | 235 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) |
|
204 | 236 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
General Comments 0
You need to be logged in to leave comments.
Login now