Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/schema/db_1_5_2.py @ 3885:712610e082e2 beta
fix unreachable code errors
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 22 May 2013 02:57:52 +0200 |
parents | ec65d8b2fccc |
children | 9345065b03c0 |
rev | line source |
---|---|
3148
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
3 rhodecode.model.db_1_5_2 |
3148
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 Database Models for RhodeCode <=1.5.X |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Apr 08, 2010 |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :author: marcink |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # (at your option) any later version. |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
26 import os |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
27 import logging |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
28 import datetime |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
29 import traceback |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
30 import hashlib |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
31 import time |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
32 from collections import defaultdict |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
33 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
34 from sqlalchemy import * |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
35 from sqlalchemy.ext.hybrid import hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
36 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
37 from sqlalchemy.exc import DatabaseError |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
38 from beaker.cache import cache_region, region_invalidate |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
39 from webob.exc import HTTPNotFound |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
40 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
41 from pylons.i18n.translation import lazy_ugettext as _ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
42 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
43 from rhodecode.lib.vcs import get_backend |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
44 from rhodecode.lib.vcs.utils.helpers import get_scm |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
45 from rhodecode.lib.vcs.exceptions import VCSError |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
46 from rhodecode.lib.vcs.utils.lazy import LazyProperty |
3710
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
47 from rhodecode.lib.vcs.backends.base import EmptyChangeset |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
48 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
49 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
50 safe_unicode, remove_suffix, remove_prefix |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
51 from rhodecode.lib.compat import json |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
52 from rhodecode.lib.caching_query import FromCache |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
53 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
54 from rhodecode.model.meta import Base, Session |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
55 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
56 URL_SEP = '/' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
57 log = logging.getLogger(__name__) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
58 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
59 #============================================================================== |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
60 # BASE CLASSES |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
61 #============================================================================== |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
62 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
63 _hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
64 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
65 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
66 class BaseModel(object): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
67 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
68 Base Model for all classess |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
69 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
70 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
71 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
72 def _get_keys(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
73 """return column names for this model """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
74 return class_mapper(cls).c.keys() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
75 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
76 def get_dict(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
77 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
78 return dict with keys and values corresponding |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
79 to this model data """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
80 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
81 d = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
82 for k in self._get_keys(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
83 d[k] = getattr(self, k) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
84 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
85 # also use __json__() if present to get additional fields |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
86 _json_attr = getattr(self, '__json__', None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
87 if _json_attr: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
88 # update with attributes from __json__ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
89 if callable(_json_attr): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
90 _json_attr = _json_attr() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
91 for k, val in _json_attr.iteritems(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
92 d[k] = val |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
93 return d |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
94 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
95 def get_appstruct(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
96 """return list with keys and values tupples corresponding |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
97 to this model data """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
98 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
99 l = [] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
100 for k in self._get_keys(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
101 l.append((k, getattr(self, k),)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
102 return l |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
103 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
104 def populate_obj(self, populate_dict): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
105 """populate model with data from given populate_dict""" |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
106 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
107 for k in self._get_keys(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
108 if k in populate_dict: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
109 setattr(self, k, populate_dict[k]) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
110 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
111 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
112 def query(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
113 return Session().query(cls) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
114 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
115 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
116 def get(cls, id_): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
117 if id_: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
118 return cls.query().get(id_) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
119 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
120 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
121 def get_or_404(cls, id_): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
122 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
123 id_ = int(id_) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
124 except (TypeError, ValueError): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
125 raise HTTPNotFound |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
126 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
127 res = cls.query().get(id_) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
128 if not res: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
129 raise HTTPNotFound |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
130 return res |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
131 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
132 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
133 def getAll(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
134 return cls.query().all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
135 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
136 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
137 def delete(cls, id_): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
138 obj = cls.query().get(id_) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
139 Session().delete(obj) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
140 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
141 def __repr__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
142 if hasattr(self, '__unicode__'): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
143 # python repr needs to return str |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
144 return safe_str(self.__unicode__()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
145 return '<DB:%s>' % (self.__class__.__name__) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
146 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
147 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
148 class RhodeCodeSetting(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
149 __tablename__ = 'rhodecode_settings' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
150 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
151 UniqueConstraint('app_settings_name'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
152 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
153 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
154 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
155 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
156 app_settings_name = Column("app_settings_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
157 _app_settings_value = Column("app_settings_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
158 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
159 def __init__(self, k='', v=''): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
160 self.app_settings_name = k |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
161 self.app_settings_value = v |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
162 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
163 @validates('_app_settings_value') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
164 def validate_settings_value(self, key, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
165 assert type(val) == unicode |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
166 return val |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
167 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
168 @hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
169 def app_settings_value(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
170 v = self._app_settings_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
171 if self.app_settings_name in ["ldap_active", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
172 "default_repo_enable_statistics", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
173 "default_repo_enable_locking", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
174 "default_repo_private", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
175 "default_repo_enable_downloads"]: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
176 v = str2bool(v) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
177 return v |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
178 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
179 @app_settings_value.setter |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
180 def app_settings_value(self, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
181 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
182 Setter that will always make sure we use unicode in app_settings_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
183 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
184 :param val: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
185 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
186 self._app_settings_value = safe_unicode(val) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
187 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
188 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
189 return u"<%s('%s:%s')>" % ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
190 self.__class__.__name__, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
191 self.app_settings_name, self.app_settings_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
192 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
193 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
194 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
195 def get_by_name(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
196 return cls.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
197 .filter(cls.app_settings_name == key).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
198 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
199 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
200 def get_by_name_or_create(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
201 res = cls.get_by_name(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
202 if not res: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
203 res = cls(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
204 return res |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
205 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
206 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
207 def get_app_settings(cls, cache=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
208 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
209 ret = cls.query() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
210 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
211 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
212 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings")) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
213 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
214 if not ret: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
215 raise Exception('Could not get application settings !') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
216 settings = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
217 for each in ret: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
218 settings['rhodecode_' + each.app_settings_name] = \ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
219 each.app_settings_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
220 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
221 return settings |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
222 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
223 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
224 def get_ldap_settings(cls, cache=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
225 ret = cls.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
226 .filter(cls.app_settings_name.startswith('ldap_')).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
227 fd = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
228 for row in ret: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
229 fd.update({row.app_settings_name: row.app_settings_value}) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
230 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
231 return fd |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
232 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
233 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
234 def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
235 ret = cls.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
236 .filter(cls.app_settings_name.startswith('default_')).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
237 fd = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
238 for row in ret: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
239 key = row.app_settings_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
240 if strip_prefix: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
241 key = remove_prefix(key, prefix='default_') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
242 fd.update({key: row.app_settings_value}) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
243 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
244 return fd |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
245 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
246 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
247 class RhodeCodeUi(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
248 __tablename__ = 'rhodecode_ui' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
249 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
250 UniqueConstraint('ui_key'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
251 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
252 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
253 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
254 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
255 HOOK_UPDATE = 'changegroup.update' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
256 HOOK_REPO_SIZE = 'changegroup.repo_size' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
257 HOOK_PUSH = 'changegroup.push_logger' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
258 HOOK_PRE_PUSH = 'prechangegroup.pre_push' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
259 HOOK_PULL = 'outgoing.pull_logger' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
260 HOOK_PRE_PULL = 'preoutgoing.pre_pull' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
261 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
262 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
263 ui_section = Column("ui_section", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
264 ui_key = Column("ui_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
265 ui_value = Column("ui_value", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
266 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
267 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
268 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
269 def get_by_key(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
270 return cls.query().filter(cls.ui_key == key).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
271 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
272 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
273 def get_builtin_hooks(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
274 q = cls.query() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
275 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
276 cls.HOOK_PUSH, cls.HOOK_PRE_PUSH, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
277 cls.HOOK_PULL, cls.HOOK_PRE_PULL])) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
278 return q.all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
279 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
280 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
281 def get_custom_hooks(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
282 q = cls.query() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
283 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
284 cls.HOOK_PUSH, cls.HOOK_PRE_PUSH, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
285 cls.HOOK_PULL, cls.HOOK_PRE_PULL])) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
286 q = q.filter(cls.ui_section == 'hooks') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
287 return q.all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
288 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
289 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
290 def get_repos_location(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
291 return cls.get_by_key('/').ui_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
292 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
293 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
294 def create_or_update_hook(cls, key, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
295 new_ui = cls.get_by_key(key) or cls() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
296 new_ui.ui_section = 'hooks' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
297 new_ui.ui_active = True |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
298 new_ui.ui_key = key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
299 new_ui.ui_value = val |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
300 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
301 Session().add(new_ui) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
302 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
303 def __repr__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
304 return '<DB:%s[%s:%s]>' % (self.__class__.__name__, self.ui_key, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
305 self.ui_value) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
306 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
307 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
308 class User(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
309 __tablename__ = 'users' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
310 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
311 UniqueConstraint('username'), UniqueConstraint('email'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
312 Index('u_username_idx', 'username'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
313 Index('u_email_idx', 'email'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
314 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
315 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
316 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
317 DEFAULT_USER = 'default' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
318 DEFAULT_PERMISSIONS = [ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
319 'hg.register.manual_activate', 'hg.create.repository', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
320 'hg.fork.repository', 'repository.read', 'group.read' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
321 ] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
322 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
323 username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
324 password = Column("password", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
325 active = Column("active", Boolean(), nullable=True, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
326 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
327 name = Column("firstname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
328 lastname = Column("lastname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
329 _email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
330 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
331 ldap_dn = Column("ldap_dn", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
332 api_key = Column("api_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
333 inherit_default_permissions = Column("inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
334 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
335 user_log = relationship('UserLog') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
336 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
337 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
338 repositories = relationship('Repository') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
339 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
340 followings = relationship('UserFollowing', primaryjoin='UserFollowing.user_id==User.user_id', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
341 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
342 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
343 repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
344 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
345 group_member = relationship('UserGroupMember', cascade='all') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
346 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
347 notifications = relationship('UserNotification', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
348 # notifications assigned to this user |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
349 user_created_notifications = relationship('Notification', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
350 # comments created by this user |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
351 user_comments = relationship('ChangesetComment', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
352 #extra emails for this user |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
353 user_emails = relationship('UserEmailMap', cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
354 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
355 @hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
356 def email(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
357 return self._email |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
358 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
359 @email.setter |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
360 def email(self, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
361 self._email = val.lower() if val else None |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
362 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
363 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
364 def firstname(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
365 # alias for future |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
366 return self.name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
367 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
368 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
369 def emails(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
370 other = UserEmailMap.query().filter(UserEmailMap.user==self).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
371 return [self.email] + [x.email for x in other] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
372 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
373 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
374 def ip_addresses(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
375 ret = UserIpMap.query().filter(UserIpMap.user == self).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
376 return [x.ip_addr for x in ret] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
377 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
378 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
379 def username_and_name(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
380 return '%s (%s %s)' % (self.username, self.firstname, self.lastname) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
381 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
382 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
383 def full_name(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
384 return '%s %s' % (self.firstname, self.lastname) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
385 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
386 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
387 def full_name_or_username(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
388 return ('%s %s' % (self.firstname, self.lastname) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
389 if (self.firstname and self.lastname) else self.username) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
390 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
391 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
392 def full_contact(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
393 return '%s %s <%s>' % (self.firstname, self.lastname, self.email) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
394 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
395 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
396 def short_contact(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
397 return '%s %s' % (self.firstname, self.lastname) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
398 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
399 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
400 def is_admin(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
401 return self.admin |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
402 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
403 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
404 return u"<%s('id:%s:%s')>" % (self.__class__.__name__, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
405 self.user_id, self.username) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
406 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
407 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
408 def get_by_username(cls, username, case_insensitive=False, cache=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
409 if case_insensitive: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
410 q = cls.query().filter(cls.username.ilike(username)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
411 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
412 q = cls.query().filter(cls.username == username) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
413 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
414 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
415 q = q.options(FromCache( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
416 "sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
417 "get_user_%s" % _hash_key(username) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
418 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
419 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
420 return q.scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
421 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
422 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
423 def get_by_api_key(cls, api_key, cache=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
424 q = cls.query().filter(cls.api_key == api_key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
425 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
426 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
427 q = q.options(FromCache("sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
428 "get_api_key_%s" % api_key)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
429 return q.scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
430 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
431 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
432 def get_by_email(cls, email, case_insensitive=False, cache=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
433 if case_insensitive: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
434 q = cls.query().filter(cls.email.ilike(email)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
435 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
436 q = cls.query().filter(cls.email == email) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
437 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
438 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
439 q = q.options(FromCache("sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
440 "get_email_key_%s" % email)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
441 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
442 ret = q.scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
443 if ret is None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
444 q = UserEmailMap.query() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
445 # try fetching in alternate email map |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
446 if case_insensitive: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
447 q = q.filter(UserEmailMap.email.ilike(email)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
448 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
449 q = q.filter(UserEmailMap.email == email) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
450 q = q.options(joinedload(UserEmailMap.user)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
451 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
452 q = q.options(FromCache("sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
453 "get_email_map_key_%s" % email)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
454 ret = getattr(q.scalar(), 'user', None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
455 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
456 return ret |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
457 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
458 def update_lastlogin(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
459 """Update user lastlogin""" |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
460 self.last_login = datetime.datetime.now() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
461 Session().add(self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
462 log.debug('updated user %s lastlogin' % self.username) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
463 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
464 def get_api_data(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
465 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
466 Common function for generating user related data for API |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
467 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
468 user = self |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
469 data = dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
470 user_id=user.user_id, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
471 username=user.username, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
472 firstname=user.name, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
473 lastname=user.lastname, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
474 email=user.email, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
475 emails=user.emails, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
476 api_key=user.api_key, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
477 active=user.active, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
478 admin=user.admin, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
479 ldap_dn=user.ldap_dn, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
480 last_login=user.last_login, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
481 ip_addresses=user.ip_addresses |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
482 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
483 return data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
484 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
485 def __json__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
486 data = dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
487 full_name=self.full_name, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
488 full_name_or_username=self.full_name_or_username, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
489 short_contact=self.short_contact, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
490 full_contact=self.full_contact |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
491 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
492 data.update(self.get_api_data()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
493 return data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
494 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
495 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
496 class UserEmailMap(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
497 __tablename__ = 'user_email_map' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
498 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
499 Index('uem_email_idx', 'email'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
500 UniqueConstraint('email'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
501 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
502 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
503 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
504 __mapper_args__ = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
505 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
506 email_id = Column("email_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
507 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
508 _email = Column("email", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
509 user = relationship('User', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
510 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
511 @validates('_email') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
512 def validate_email(self, key, email): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
513 # check if this email is not main one |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
514 main_email = Session().query(User).filter(User.email == email).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
515 if main_email is not None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
516 raise AttributeError('email %s is present is user table' % email) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
517 return email |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
518 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
519 @hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
520 def email(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
521 return self._email |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
522 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
523 @email.setter |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
524 def email(self, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
525 self._email = val.lower() if val else None |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
526 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
527 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
528 class UserIpMap(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
529 __tablename__ = 'user_ip_map' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
530 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
531 UniqueConstraint('user_id', 'ip_addr'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
532 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
533 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
534 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
535 __mapper_args__ = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
536 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
537 ip_id = Column("ip_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
538 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
539 ip_addr = Column("ip_addr", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
540 active = Column("active", Boolean(), nullable=True, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
541 user = relationship('User', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
542 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
543 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
544 def _get_ip_range(cls, ip_addr): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
545 from rhodecode.lib import ipaddr |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
546 net = ipaddr.IPv4Network(ip_addr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
547 return [str(net.network), str(net.broadcast)] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
548 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
549 def __json__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
550 return dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
551 ip_addr=self.ip_addr, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
552 ip_range=self._get_ip_range(self.ip_addr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
553 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
554 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
555 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
556 class UserLog(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
557 __tablename__ = 'user_logs' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
558 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
559 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
560 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
561 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
562 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
563 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
564 username = Column("username", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
565 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
566 repository_name = Column("repository_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
567 user_ip = Column("user_ip", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
568 action = Column("action", UnicodeText(1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
569 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
570 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
571 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
572 def action_as_day(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
573 return datetime.date(*self.action_date.timetuple()[:3]) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
574 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
575 user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
576 repository = relationship('Repository', cascade='') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
577 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
578 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
579 class UserGroup(Base, BaseModel): |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
580 __tablename__ = 'users_groups' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
581 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
582 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
583 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
584 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
585 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
586 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
587 users_group_name = Column("users_group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
588 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
589 inherit_default_permissions = Column("users_group_inherit_default_permissions", Boolean(), nullable=False, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
590 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
591 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
592 users_group_to_perm = relationship('UserGroupToPerm', cascade='all') |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
593 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
594 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
595 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
596 return u'<userGroup(%s)>' % (self.users_group_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
597 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
598 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
599 def get_by_group_name(cls, group_name, cache=False, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
600 case_insensitive=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
601 if case_insensitive: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
602 q = cls.query().filter(cls.users_group_name.ilike(group_name)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
603 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
604 q = cls.query().filter(cls.users_group_name == group_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
605 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
606 q = q.options(FromCache( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
607 "sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
608 "get_user_%s" % _hash_key(group_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
609 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
610 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
611 return q.scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
612 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
613 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
614 def get(cls, users_group_id, cache=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
615 users_group = cls.query() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
616 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
617 users_group = users_group.options(FromCache("sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
618 "get_users_group_%s" % users_group_id)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
619 return users_group.get(users_group_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
620 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
621 def get_api_data(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
622 users_group = self |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
623 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
624 data = dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
625 users_group_id=users_group.users_group_id, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
626 group_name=users_group.users_group_name, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
627 active=users_group.users_group_active, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
628 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
629 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
630 return data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
631 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
632 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
633 class UserGroupMember(Base, BaseModel): |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
634 __tablename__ = 'users_groups_members' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
635 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
636 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
637 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
638 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
639 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
640 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
641 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
642 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
643 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
644 user = relationship('User', lazy='joined') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
645 users_group = relationship('UserGroup') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
646 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
647 def __init__(self, gr_id='', u_id=''): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
648 self.users_group_id = gr_id |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
649 self.user_id = u_id |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
650 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
651 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
652 class Repository(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
653 __tablename__ = 'repositories' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
654 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
655 UniqueConstraint('repo_name'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
656 Index('r_repo_name_idx', 'repo_name'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
657 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
658 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
659 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
660 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
661 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
662 repo_name = Column("repo_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
663 clone_uri = Column("clone_uri", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
664 repo_type = Column("repo_type", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
665 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
666 private = Column("private", Boolean(), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
667 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
668 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
669 description = Column("description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
670 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
671 updated_on = Column('updated_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
672 landing_rev = Column("landing_revision", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
673 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
674 _locked = Column("locked", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
675 _changeset_cache = Column("changeset_cache", LargeBinary(), nullable=True) #JSON data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
676 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
677 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
678 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
679 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
680 user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
681 fork = relationship('Repository', remote_side=repo_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
682 group = relationship('RepoGroup') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
683 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
684 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
685 stats = relationship('Statistics', cascade='all', uselist=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
686 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
687 followers = relationship('UserFollowing', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
688 primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
689 cascade='all') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
690 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
691 logs = relationship('UserLog') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
692 comments = relationship('ChangesetComment', cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
693 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
694 pull_requests_org = relationship('PullRequest', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
695 primaryjoin='PullRequest.org_repo_id==Repository.repo_id', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
696 cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
697 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
698 pull_requests_other = relationship('PullRequest', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
699 primaryjoin='PullRequest.other_repo_id==Repository.repo_id', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
700 cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
701 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
702 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
703 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.repo_id, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
704 self.repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
705 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
706 @hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
707 def locked(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
708 # always should return [user_id, timelocked] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
709 if self._locked: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
710 _lock_info = self._locked.split(':') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
711 return int(_lock_info[0]), _lock_info[1] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
712 return [None, None] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
713 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
714 @locked.setter |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
715 def locked(self, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
716 if val and isinstance(val, (list, tuple)): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
717 self._locked = ':'.join(map(str, val)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
718 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
719 self._locked = None |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
720 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
721 @hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
722 def changeset_cache(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
723 from rhodecode.lib.vcs.backends.base import EmptyChangeset |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
724 dummy = EmptyChangeset().__json__() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
725 if not self._changeset_cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
726 return dummy |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
727 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
728 return json.loads(self._changeset_cache) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
729 except TypeError: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
730 return dummy |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
731 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
732 @changeset_cache.setter |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
733 def changeset_cache(self, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
734 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
735 self._changeset_cache = json.dumps(val) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
736 except: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
737 log.error(traceback.format_exc()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
738 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
739 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
740 def url_sep(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
741 return URL_SEP |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
742 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
743 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
744 def normalize_repo_name(cls, repo_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
745 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
746 Normalizes os specific repo_name to the format internally stored inside |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
747 dabatabase using URL_SEP |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
748 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
749 :param cls: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
750 :param repo_name: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
751 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
752 return cls.url_sep().join(repo_name.split(os.sep)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
753 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
754 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
755 def get_by_repo_name(cls, repo_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
756 q = Session().query(cls).filter(cls.repo_name == repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
757 q = q.options(joinedload(Repository.fork))\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
758 .options(joinedload(Repository.user))\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
759 .options(joinedload(Repository.group)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
760 return q.scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
761 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
762 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
763 def get_by_full_path(cls, repo_full_path): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
764 repo_name = repo_full_path.split(cls.base_path(), 1)[-1] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
765 repo_name = cls.normalize_repo_name(repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
766 return cls.get_by_repo_name(repo_name.strip(URL_SEP)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
767 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
768 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
769 def get_repo_forks(cls, repo_id): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
770 return cls.query().filter(Repository.fork_id == repo_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
771 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
772 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
773 def base_path(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
774 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
775 Returns base path when all repos are stored |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
776 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
777 :param cls: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
778 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
779 q = Session().query(RhodeCodeUi)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
780 .filter(RhodeCodeUi.ui_key == cls.url_sep()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
781 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
782 return q.one().ui_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
783 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
784 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
785 def forks(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
786 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
787 Return forks of this repo |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
788 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
789 return Repository.get_repo_forks(self.repo_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
790 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
791 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
792 def parent(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
793 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
794 Returns fork parent |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
795 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
796 return self.fork |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
797 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
798 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
799 def just_name(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
800 return self.repo_name.split(Repository.url_sep())[-1] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
801 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
802 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
803 def groups_with_parents(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
804 groups = [] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
805 if self.group is None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
806 return groups |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
807 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
808 cur_gr = self.group |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
809 groups.insert(0, cur_gr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
810 while 1: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
811 gr = getattr(cur_gr, 'parent_group', None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
812 cur_gr = cur_gr.parent_group |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
813 if gr is None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
814 break |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
815 groups.insert(0, gr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
816 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
817 return groups |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
818 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
819 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
820 def groups_and_repo(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
821 return self.groups_with_parents, self.just_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
822 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
823 @LazyProperty |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
824 def repo_path(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
825 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
826 Returns base full path for that repository means where it actually |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
827 exists on a filesystem |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
828 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
829 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
830 Repository.url_sep()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
831 q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
832 return q.one().ui_value |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
833 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
834 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
835 def repo_full_path(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
836 p = [self.repo_path] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
837 # we need to split the name by / since this is how we store the |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
838 # names in the database, but that eventually needs to be converted |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
839 # into a valid system path |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
840 p += self.repo_name.split(Repository.url_sep()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
841 return os.path.join(*p) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
842 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
843 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
844 def cache_keys(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
845 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
846 Returns associated cache keys for that repo |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
847 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
848 return CacheInvalidation.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
849 .filter(CacheInvalidation.cache_args == self.repo_name)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
850 .order_by(CacheInvalidation.cache_key)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
851 .all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
852 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
853 def get_new_name(self, repo_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
854 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
855 returns new full repository name based on assigned group and new new |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
856 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
857 :param group_name: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
858 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
859 path_prefix = self.group.full_path_splitted if self.group else [] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
860 return Repository.url_sep().join(path_prefix + [repo_name]) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
861 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
862 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
863 def _ui(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
864 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
865 Creates an db based ui object for this repository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
866 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
867 from rhodecode.lib.utils import make_ui |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
868 return make_ui('db', clear_session=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
869 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
870 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
871 def inject_ui(cls, repo, extras={}): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
872 from rhodecode.lib.vcs.backends.hg import MercurialRepository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
873 from rhodecode.lib.vcs.backends.git import GitRepository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
874 required = (MercurialRepository, GitRepository) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
875 if not isinstance(repo, required): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
876 raise Exception('repo must be instance of %s' % required) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
877 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
878 # inject ui extra param to log this action via push logger |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
879 for k, v in extras.items(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
880 repo._repo.ui.setconfig('rhodecode_extras', k, v) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
881 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
882 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
883 def is_valid(cls, repo_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
884 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
885 returns True if given repo name is a valid filesystem repository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
886 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
887 :param cls: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
888 :param repo_name: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
889 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
890 from rhodecode.lib.utils import is_valid_repo |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
891 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
892 return is_valid_repo(repo_name, cls.base_path()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
893 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
894 def get_api_data(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
895 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
896 Common function for generating repo api data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
897 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
898 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
899 repo = self |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
900 data = dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
901 repo_id=repo.repo_id, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
902 repo_name=repo.repo_name, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
903 repo_type=repo.repo_type, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
904 clone_uri=repo.clone_uri, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
905 private=repo.private, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
906 created_on=repo.created_on, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
907 description=repo.description, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
908 landing_rev=repo.landing_rev, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
909 owner=repo.user.username, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
910 fork_of=repo.fork.repo_name if repo.fork else None, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
911 enable_statistics=repo.enable_statistics, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
912 enable_locking=repo.enable_locking, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
913 enable_downloads=repo.enable_downloads, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
914 last_changeset=repo.changeset_cache |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
915 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
916 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
917 return data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
918 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
919 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
920 def lock(cls, repo, user_id): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
921 repo.locked = [user_id, time.time()] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
922 Session().add(repo) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
923 Session().commit() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
924 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
925 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
926 def unlock(cls, repo): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
927 repo.locked = None |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
928 Session().add(repo) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
929 Session().commit() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
930 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
931 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
932 def last_db_change(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
933 return self.updated_on |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
934 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
935 def clone_url(self, **override): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
936 from pylons import url |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
937 from urlparse import urlparse |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
938 import urllib |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
939 parsed_url = urlparse(url('home', qualified=True)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
940 default_clone_uri = '%(scheme)s://%(user)s%(pass)s%(netloc)s%(prefix)s%(path)s' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
941 decoded_path = safe_unicode(urllib.unquote(parsed_url.path)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
942 args = { |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
943 'user': '', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
944 'pass': '', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
945 'scheme': parsed_url.scheme, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
946 'netloc': parsed_url.netloc, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
947 'prefix': decoded_path, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
948 'path': self.repo_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
949 } |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
950 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
951 args.update(override) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
952 return default_clone_uri % args |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
953 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
954 #========================================================================== |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
955 # SCM PROPERTIES |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
956 #========================================================================== |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
957 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
958 def get_changeset(self, rev=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
959 return get_changeset_safe(self.scm_instance, rev) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
960 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
961 def get_landing_changeset(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
962 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
963 Returns landing changeset, or if that doesn't exist returns the tip |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
964 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
965 cs = self.get_changeset(self.landing_rev) or self.get_changeset() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
966 return cs |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
967 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
968 def update_changeset_cache(self, cs_cache=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
969 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
970 Update cache of last changeset for repository, keys should be:: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
971 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
972 short_id |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
973 raw_id |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
974 revision |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
975 message |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
976 date |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
977 author |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
978 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
979 :param cs_cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
980 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
981 from rhodecode.lib.vcs.backends.base import BaseChangeset |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
982 if cs_cache is None: |
3710
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
983 cs_cache = EmptyChangeset() |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
984 # use no-cache version here |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
985 scm_repo = self.scm_instance_no_cache() |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
986 if scm_repo: |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
987 cs_cache = scm_repo.get_changeset() |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
988 |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
989 if isinstance(cs_cache, BaseChangeset): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
990 cs_cache = cs_cache.__json__() |
3148
b31984972e95
Migration upgrades cache for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
991 |
3710
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
992 if (cs_cache != self.changeset_cache or not self.changeset_cache): |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
993 _default = datetime.datetime.fromtimestamp(0) |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
994 last_change = cs_cache.get('date') or _default |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
995 log.debug('updated repo %s with new cs cache %s' |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
996 % (self.repo_name, cs_cache)) |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
997 self.updated_on = last_change |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
998 self.changeset_cache = cs_cache |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
999 Session().add(self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1000 Session().commit() |
3710
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
1001 else: |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
1002 log.debug('Skipping repo:%s already with latest changes' |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
1003 % self.repo_name) |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1004 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1005 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1006 def tip(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1007 return self.get_changeset('tip') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1008 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1009 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1010 def author(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1011 return self.tip.author |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1012 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1013 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1014 def last_change(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1015 return self.scm_instance.last_change |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1016 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1017 def get_comments(self, revisions=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1018 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1019 Returns comments for this repository grouped by revisions |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1020 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1021 :param revisions: filter query by revisions only |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1022 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1023 cmts = ChangesetComment.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1024 .filter(ChangesetComment.repo == self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1025 if revisions: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1026 cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1027 grouped = defaultdict(list) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1028 for cmt in cmts.all(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1029 grouped[cmt.revision].append(cmt) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1030 return grouped |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1031 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1032 def statuses(self, revisions=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1033 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1034 Returns statuses for this repository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1035 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1036 :param revisions: list of revisions to get statuses for |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1037 :type revisions: list |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1038 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1039 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1040 statuses = ChangesetStatus.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1041 .filter(ChangesetStatus.repo == self)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1042 .filter(ChangesetStatus.version == 0) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1043 if revisions: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1044 statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1045 grouped = {} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1046 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1047 #maybe we have open new pullrequest without a status ? |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1048 stat = ChangesetStatus.STATUS_UNDER_REVIEW |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1049 status_lbl = ChangesetStatus.get_status_lbl(stat) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1050 for pr in PullRequest.query().filter(PullRequest.org_repo == self).all(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1051 for rev in pr.revisions: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1052 pr_id = pr.pull_request_id |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1053 pr_repo = pr.other_repo.repo_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1054 grouped[rev] = [stat, status_lbl, pr_id, pr_repo] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1055 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1056 for stat in statuses.all(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1057 pr_id = pr_repo = None |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1058 if stat.pull_request: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1059 pr_id = stat.pull_request.pull_request_id |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1060 pr_repo = stat.pull_request.other_repo.repo_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1061 grouped[stat.revision] = [str(stat.status), stat.status_lbl, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1062 pr_id, pr_repo] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1063 return grouped |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1064 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1065 #========================================================================== |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1066 # SCM CACHE INSTANCE |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1067 #========================================================================== |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1068 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1069 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1070 def invalidate(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1071 return CacheInvalidation.invalidate(self.repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1072 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1073 def set_invalidate(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1074 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1075 set a cache for invalidation for this instance |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1076 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1077 CacheInvalidation.set_invalidate(repo_name=self.repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1078 |
3710
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
1079 def scm_instance_no_cache(self): |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
1080 return self.__get_instance() |
ec65d8b2fccc
freeze schema for 1.6 + fixed migration from version 1.4.X+
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
1081 |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1082 @LazyProperty |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1083 def scm_instance(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1084 import rhodecode |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1085 full_cache = str2bool(rhodecode.CONFIG.get('vcs_full_cache')) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1086 if full_cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1087 return self.scm_instance_cached() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1088 return self.__get_instance() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1089 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1090 def scm_instance_cached(self, cache_map=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1091 @cache_region('long_term') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1092 def _c(repo_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1093 return self.__get_instance() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1094 rn = self.repo_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1095 log.debug('Getting cached instance of repo') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1096 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1097 if cache_map: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1098 # get using prefilled cache_map |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1099 invalidate_repo = cache_map[self.repo_name] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1100 if invalidate_repo: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1101 invalidate_repo = (None if invalidate_repo.cache_active |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1102 else invalidate_repo) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1103 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1104 # get from invalidate |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1105 invalidate_repo = self.invalidate |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1106 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1107 if invalidate_repo is not None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1108 region_invalidate(_c, None, rn) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1109 # update our cache |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1110 CacheInvalidation.set_valid(invalidate_repo.cache_key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1111 return _c(rn) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1112 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1113 def __get_instance(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1114 repo_full_path = self.repo_full_path |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1115 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1116 alias = get_scm(repo_full_path)[0] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1117 log.debug('Creating instance of %s repository' % alias) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1118 backend = get_backend(alias) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1119 except VCSError: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1120 log.error(traceback.format_exc()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1121 log.error('Perhaps this repository is in db and not in ' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1122 'filesystem run rescan repositories with ' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1123 '"destroy old data " option from admin panel') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1124 return |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1125 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1126 if alias == 'hg': |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1127 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1128 repo = backend(safe_str(repo_full_path), create=False, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1129 baseui=self._ui) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1130 # skip hidden web repository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1131 if repo._get_hidden(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1132 return |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1133 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1134 repo = backend(repo_full_path, create=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1135 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1136 return repo |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1137 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1138 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1139 class RepoGroup(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1140 __tablename__ = 'groups' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1141 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1142 UniqueConstraint('group_name', 'group_parent_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1143 CheckConstraint('group_id != group_parent_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1144 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1145 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1146 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1147 __mapper_args__ = {'order_by': 'group_name'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1148 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1149 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1150 group_name = Column("group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1151 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1152 group_description = Column("group_description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1153 enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1154 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1155 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1156 users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1157 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1158 parent_group = relationship('RepoGroup', remote_side=group_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1159 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1160 def __init__(self, group_name='', parent_group=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1161 self.group_name = group_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1162 self.parent_group = parent_group |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1163 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1164 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1165 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1166 self.group_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1167 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1168 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1169 def groups_choices(cls, check_perms=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1170 from webhelpers.html import literal as _literal |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1171 from rhodecode.model.scm import ScmModel |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1172 groups = cls.query().all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1173 if check_perms: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1174 #filter group user have access to, it's done |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1175 #magically inside ScmModel based on current user |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1176 groups = ScmModel().get_repos_groups(groups) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1177 repo_groups = [('', '')] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1178 sep = ' » ' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1179 _name = lambda k: _literal(sep.join(k)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1180 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1181 repo_groups.extend([(x.group_id, _name(x.full_path_splitted)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1182 for x in groups]) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1183 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1184 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0]) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1185 return repo_groups |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1186 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1187 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1188 def url_sep(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1189 return URL_SEP |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1190 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1191 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1192 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1193 if case_insensitive: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1194 gr = cls.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1195 .filter(cls.group_name.ilike(group_name)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1196 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1197 gr = cls.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1198 .filter(cls.group_name == group_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1199 if cache: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1200 gr = gr.options(FromCache( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1201 "sql_cache_short", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1202 "get_group_%s" % _hash_key(group_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1203 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1204 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1205 return gr.scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1206 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1207 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1208 def parents(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1209 parents_recursion_limit = 5 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1210 groups = [] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1211 if self.parent_group is None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1212 return groups |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1213 cur_gr = self.parent_group |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1214 groups.insert(0, cur_gr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1215 cnt = 0 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1216 while 1: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1217 cnt += 1 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1218 gr = getattr(cur_gr, 'parent_group', None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1219 cur_gr = cur_gr.parent_group |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1220 if gr is None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1221 break |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1222 if cnt == parents_recursion_limit: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1223 # this will prevent accidental infinit loops |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1224 log.error('group nested more than %s' % |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1225 parents_recursion_limit) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1226 break |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1227 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1228 groups.insert(0, gr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1229 return groups |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1230 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1231 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1232 def children(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1233 return RepoGroup.query().filter(RepoGroup.parent_group == self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1234 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1235 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1236 def name(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1237 return self.group_name.split(RepoGroup.url_sep())[-1] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1238 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1239 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1240 def full_path(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1241 return self.group_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1242 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1243 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1244 def full_path_splitted(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1245 return self.group_name.split(RepoGroup.url_sep()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1246 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1247 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1248 def repositories(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1249 return Repository.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1250 .filter(Repository.group == self)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1251 .order_by(Repository.repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1252 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1253 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1254 def repositories_recursive_count(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1255 cnt = self.repositories.count() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1256 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1257 def children_count(group): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1258 cnt = 0 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1259 for child in group.children: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1260 cnt += child.repositories.count() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1261 cnt += children_count(child) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1262 return cnt |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1263 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1264 return cnt + children_count(self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1265 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1266 def recursive_groups_and_repos(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1267 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1268 Recursive return all groups, with repositories in those groups |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1269 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1270 all_ = [] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1271 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1272 def _get_members(root_gr): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1273 for r in root_gr.repositories: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1274 all_.append(r) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1275 childs = root_gr.children.all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1276 if childs: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1277 for gr in childs: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1278 all_.append(gr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1279 _get_members(gr) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1280 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1281 _get_members(self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1282 return [self] + all_ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1283 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1284 def get_new_name(self, group_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1285 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1286 returns new full group name based on parent and new name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1287 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1288 :param group_name: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1289 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1290 path_prefix = (self.parent_group.full_path_splitted if |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1291 self.parent_group else []) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1292 return RepoGroup.url_sep().join(path_prefix + [group_name]) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1293 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1294 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1295 class Permission(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1296 __tablename__ = 'permissions' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1297 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1298 Index('p_perm_name_idx', 'permission_name'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1299 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1300 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1301 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1302 PERMS = [ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1303 ('repository.none', _('Repository no access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1304 ('repository.read', _('Repository read access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1305 ('repository.write', _('Repository write access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1306 ('repository.admin', _('Repository admin access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1307 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1308 ('group.none', _('Repositories Group no access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1309 ('group.read', _('Repositories Group read access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1310 ('group.write', _('Repositories Group write access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1311 ('group.admin', _('Repositories Group admin access')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1312 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1313 ('hg.admin', _('RhodeCode Administrator')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1314 ('hg.create.none', _('Repository creation disabled')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1315 ('hg.create.repository', _('Repository creation enabled')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1316 ('hg.fork.none', _('Repository forking disabled')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1317 ('hg.fork.repository', _('Repository forking enabled')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1318 ('hg.register.none', _('Register disabled')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1319 ('hg.register.manual_activate', _('Register new user with RhodeCode ' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1320 'with manual activation')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1321 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1322 ('hg.register.auto_activate', _('Register new user with RhodeCode ' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1323 'with auto activation')), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1324 ] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1325 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1326 # defines which permissions are more important higher the more important |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1327 PERM_WEIGHTS = { |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1328 'repository.none': 0, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1329 'repository.read': 1, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1330 'repository.write': 3, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1331 'repository.admin': 4, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1332 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1333 'group.none': 0, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1334 'group.read': 1, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1335 'group.write': 3, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1336 'group.admin': 4, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1337 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1338 'hg.fork.none': 0, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1339 'hg.fork.repository': 1, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1340 'hg.create.none': 0, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1341 'hg.create.repository':1 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1342 } |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1343 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1344 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1345 permission_name = Column("permission_name", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1346 permission_longname = Column("permission_longname", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1347 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1348 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1349 return u"<%s('%s:%s')>" % ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1350 self.__class__.__name__, self.permission_id, self.permission_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1351 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1352 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1353 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1354 def get_by_key(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1355 return cls.query().filter(cls.permission_name == key).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1356 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1357 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1358 def get_default_perms(cls, default_user_id): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1359 q = Session().query(UserRepoToPerm, Repository, cls)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1360 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1361 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1362 .filter(UserRepoToPerm.user_id == default_user_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1363 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1364 return q.all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1365 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1366 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1367 def get_default_group_perms(cls, default_user_id): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1368 q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1369 .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1370 .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1371 .filter(UserRepoGroupToPerm.user_id == default_user_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1372 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1373 return q.all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1374 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1375 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1376 class UserRepoToPerm(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1377 __tablename__ = 'repo_to_perm' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1378 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1379 UniqueConstraint('user_id', 'repository_id', 'permission_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1380 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1381 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1382 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1383 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1384 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1385 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1386 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1387 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1388 user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1389 repository = relationship('Repository') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1390 permission = relationship('Permission') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1391 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1392 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1393 def create(cls, user, repository, permission): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1394 n = cls() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1395 n.user = user |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1396 n.repository = repository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1397 n.permission = permission |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1398 Session().add(n) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1399 return n |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1400 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1401 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1402 return u'<user:%s => %s >' % (self.user, self.repository) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1403 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1404 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1405 class UserToPerm(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1406 __tablename__ = 'user_to_perm' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1407 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1408 UniqueConstraint('user_id', 'permission_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1409 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1410 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1411 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1412 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1413 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1414 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1415 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1416 user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1417 permission = relationship('Permission', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1418 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1419 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1420 class UserGroupRepoToPerm(Base, BaseModel): |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1421 __tablename__ = 'users_group_repo_to_perm' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1422 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1423 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1424 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1425 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1426 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1427 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1428 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1429 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1430 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1431 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1432 users_group = relationship('UserGroup') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1433 permission = relationship('Permission') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1434 repository = relationship('Repository') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1435 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1436 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1437 def create(cls, users_group, repository, permission): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1438 n = cls() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1439 n.users_group = users_group |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1440 n.repository = repository |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1441 n.permission = permission |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1442 Session().add(n) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1443 return n |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1444 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1445 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1446 return u'<userGroup:%s => %s >' % (self.users_group, self.repository) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1447 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1448 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1449 class UserGroupToPerm(Base, BaseModel): |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1450 __tablename__ = 'users_group_to_perm' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1451 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1452 UniqueConstraint('users_group_id', 'permission_id',), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1453 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1454 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1455 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1456 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1457 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1458 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1459 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1460 users_group = relationship('UserGroup') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1461 permission = relationship('Permission') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1462 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1463 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1464 class UserRepoGroupToPerm(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1465 __tablename__ = 'user_repo_group_to_perm' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1466 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1467 UniqueConstraint('user_id', 'group_id', 'permission_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1468 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1469 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1470 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1471 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1472 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1473 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1474 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1475 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1476 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1477 user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1478 group = relationship('RepoGroup') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1479 permission = relationship('Permission') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1480 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1481 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1482 class UserGroupRepoGroupToPerm(Base, BaseModel): |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1483 __tablename__ = 'users_group_repo_group_to_perm' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1484 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1485 UniqueConstraint('users_group_id', 'group_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1486 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1487 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1488 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1489 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1490 users_group_repo_group_to_perm_id = Column("users_group_repo_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1491 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1492 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1493 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1494 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3308
diff
changeset
|
1495 users_group = relationship('UserGroup') |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1496 permission = relationship('Permission') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1497 group = relationship('RepoGroup') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1498 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1499 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1500 class Statistics(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1501 __tablename__ = 'statistics' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1502 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1503 UniqueConstraint('repository_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1504 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1505 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1506 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1507 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1508 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1509 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1510 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1511 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1512 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1513 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1514 repository = relationship('Repository', single_parent=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1515 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1516 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1517 class UserFollowing(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1518 __tablename__ = 'user_followings' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1519 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1520 UniqueConstraint('user_id', 'follows_repository_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1521 UniqueConstraint('user_id', 'follows_user_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1522 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1523 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1524 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1525 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1526 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1527 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1528 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1529 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1530 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1531 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1532 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1533 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1534 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1535 follows_repository = relationship('Repository', order_by='Repository.repo_name') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1536 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1537 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1538 def get_repo_followers(cls, repo_id): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1539 return cls.query().filter(cls.follows_repo_id == repo_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1540 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1541 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1542 class CacheInvalidation(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1543 __tablename__ = 'cache_invalidation' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1544 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1545 UniqueConstraint('cache_key'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1546 Index('key_idx', 'cache_key'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1547 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1548 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1549 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1550 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1551 cache_key = Column("cache_key", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1552 cache_args = Column("cache_args", String(255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1553 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1554 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1555 def __init__(self, cache_key, cache_args=''): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1556 self.cache_key = cache_key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1557 self.cache_args = cache_args |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1558 self.cache_active = False |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1559 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1560 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1561 return u"<%s('%s:%s')>" % (self.__class__.__name__, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1562 self.cache_id, self.cache_key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1563 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1564 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1565 def prefix(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1566 _split = self.cache_key.split(self.cache_args, 1) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1567 if _split and len(_split) == 2: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1568 return _split[0] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1569 return '' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1570 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1571 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1572 def clear_cache(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1573 cls.query().delete() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1574 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1575 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1576 def _get_key(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1577 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1578 Wrapper for generating a key, together with a prefix |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1579 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1580 :param key: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1581 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1582 import rhodecode |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1583 prefix = '' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1584 org_key = key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1585 iid = rhodecode.CONFIG.get('instance_id') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1586 if iid: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1587 prefix = iid |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1588 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1589 return "%s%s" % (prefix, key), prefix, org_key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1590 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1591 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1592 def get_by_key(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1593 return cls.query().filter(cls.cache_key == key).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1594 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1595 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1596 def get_by_repo_name(cls, repo_name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1597 return cls.query().filter(cls.cache_args == repo_name).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1598 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1599 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1600 def _get_or_create_key(cls, key, repo_name, commit=True): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1601 inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1602 if not inv_obj: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1603 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1604 inv_obj = CacheInvalidation(key, repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1605 Session().add(inv_obj) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1606 if commit: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1607 Session().commit() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1608 except Exception: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1609 log.error(traceback.format_exc()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1610 Session().rollback() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1611 return inv_obj |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1612 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1613 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1614 def invalidate(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1615 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1616 Returns Invalidation object if this given key should be invalidated |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1617 None otherwise. `cache_active = False` means that this cache |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1618 state is not valid and needs to be invalidated |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1619 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1620 :param key: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1621 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1622 repo_name = key |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1623 repo_name = remove_suffix(repo_name, '_README') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1624 repo_name = remove_suffix(repo_name, '_RSS') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1625 repo_name = remove_suffix(repo_name, '_ATOM') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1626 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1627 # adds instance prefix |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1628 key, _prefix, _org_key = cls._get_key(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1629 inv = cls._get_or_create_key(key, repo_name) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1630 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1631 if inv and inv.cache_active is False: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1632 return inv |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1633 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1634 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1635 def set_invalidate(cls, key=None, repo_name=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1636 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1637 Mark this Cache key for invalidation, either by key or whole |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1638 cache sets based on repo_name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1639 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1640 :param key: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1641 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1642 if key: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1643 key, _prefix, _org_key = cls._get_key(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1644 inv_objs = Session().query(cls).filter(cls.cache_key == key).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1645 elif repo_name: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1646 inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1647 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1648 log.debug('marking %s key[s] for invalidation based on key=%s,repo_name=%s' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1649 % (len(inv_objs), key, repo_name)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1650 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1651 for inv_obj in inv_objs: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1652 inv_obj.cache_active = False |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1653 Session().add(inv_obj) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1654 Session().commit() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1655 except Exception: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1656 log.error(traceback.format_exc()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1657 Session().rollback() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1658 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1659 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1660 def set_valid(cls, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1661 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1662 Mark this cache key as active and currently cached |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1663 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1664 :param key: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1665 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1666 inv_obj = cls.get_by_key(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1667 inv_obj.cache_active = True |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1668 Session().add(inv_obj) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1669 Session().commit() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1670 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1671 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1672 def get_cache_map(cls): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1673 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1674 class cachemapdict(dict): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1675 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1676 def __init__(self, *args, **kwargs): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1677 fixkey = kwargs.get('fixkey') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1678 if fixkey: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1679 del kwargs['fixkey'] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1680 self.fixkey = fixkey |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1681 super(cachemapdict, self).__init__(*args, **kwargs) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1682 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1683 def __getattr__(self, name): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1684 key = name |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1685 if self.fixkey: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1686 key, _prefix, _org_key = cls._get_key(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1687 if key in self.__dict__: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1688 return self.__dict__[key] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1689 else: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1690 return self[key] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1691 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1692 def __getitem__(self, key): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1693 if self.fixkey: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1694 key, _prefix, _org_key = cls._get_key(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1695 try: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1696 return super(cachemapdict, self).__getitem__(key) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1697 except KeyError: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1698 return |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1699 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1700 cache_map = cachemapdict(fixkey=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1701 for obj in cls.query().all(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1702 cache_map[obj.cache_key] = cachemapdict(obj.get_dict()) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1703 return cache_map |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1704 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1705 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1706 class ChangesetComment(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1707 __tablename__ = 'changeset_comments' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1708 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1709 Index('cc_revision_idx', 'revision'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1710 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1711 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1712 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1713 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1714 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1715 revision = Column('revision', String(40), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1716 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1717 line_no = Column('line_no', Unicode(10), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1718 hl_lines = Column('hl_lines', Unicode(512), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1719 f_path = Column('f_path', Unicode(1000), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1720 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1721 text = Column('text', UnicodeText(25000), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1722 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1723 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1724 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1725 author = relationship('User', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1726 repo = relationship('Repository') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1727 status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1728 pull_request = relationship('PullRequest', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1729 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1730 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1731 def get_users(cls, revision=None, pull_request_id=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1732 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1733 Returns user associated with this ChangesetComment. ie those |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1734 who actually commented |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1735 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1736 :param cls: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1737 :param revision: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1738 """ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1739 q = Session().query(User)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1740 .join(ChangesetComment.author) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1741 if revision: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1742 q = q.filter(cls.revision == revision) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1743 elif pull_request_id: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1744 q = q.filter(cls.pull_request_id == pull_request_id) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1745 return q.all() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1746 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1747 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1748 class ChangesetStatus(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1749 __tablename__ = 'changeset_statuses' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1750 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1751 Index('cs_revision_idx', 'revision'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1752 Index('cs_version_idx', 'version'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1753 UniqueConstraint('repo_id', 'revision', 'version'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1754 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1755 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1756 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1757 STATUS_NOT_REVIEWED = DEFAULT = 'not_reviewed' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1758 STATUS_APPROVED = 'approved' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1759 STATUS_REJECTED = 'rejected' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1760 STATUS_UNDER_REVIEW = 'under_review' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1761 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1762 STATUSES = [ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1763 (STATUS_NOT_REVIEWED, _("Not Reviewed")), # (no icon) and default |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1764 (STATUS_APPROVED, _("Approved")), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1765 (STATUS_REJECTED, _("Rejected")), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1766 (STATUS_UNDER_REVIEW, _("Under Review")), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1767 ] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1768 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1769 changeset_status_id = Column('changeset_status_id', Integer(), nullable=False, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1770 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1771 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1772 revision = Column('revision', String(40), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1773 status = Column('status', String(128), nullable=False, default=DEFAULT) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1774 changeset_comment_id = Column('changeset_comment_id', Integer(), ForeignKey('changeset_comments.comment_id')) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1775 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1776 version = Column('version', Integer(), nullable=False, default=0) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1777 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1778 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1779 author = relationship('User', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1780 repo = relationship('Repository') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1781 comment = relationship('ChangesetComment', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1782 pull_request = relationship('PullRequest', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1783 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1784 def __unicode__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1785 return u"<%s('%s:%s')>" % ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1786 self.__class__.__name__, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1787 self.status, self.author |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1788 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1789 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1790 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1791 def get_status_lbl(cls, value): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1792 return dict(cls.STATUSES).get(value) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1793 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1794 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1795 def status_lbl(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1796 return ChangesetStatus.get_status_lbl(self.status) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1797 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1798 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1799 class PullRequest(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1800 __tablename__ = 'pull_requests' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1801 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1802 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1803 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1804 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1805 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1806 STATUS_NEW = u'new' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1807 STATUS_OPEN = u'open' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1808 STATUS_CLOSED = u'closed' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1809 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1810 pull_request_id = Column('pull_request_id', Integer(), nullable=False, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1811 title = Column('title', Unicode(256), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1812 description = Column('description', UnicodeText(10240), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1813 status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1814 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1815 updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1816 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1817 _revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1818 org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1819 org_ref = Column('org_ref', Unicode(256), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1820 other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1821 other_ref = Column('other_ref', Unicode(256), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1822 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1823 @hybrid_property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1824 def revisions(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1825 return self._revisions.split(':') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1826 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1827 @revisions.setter |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1828 def revisions(self, val): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1829 self._revisions = ':'.join(val) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1830 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1831 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1832 def org_ref_parts(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1833 return self.org_ref.split(':') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1834 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1835 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1836 def other_ref_parts(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1837 return self.other_ref.split(':') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1838 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1839 author = relationship('User', lazy='joined') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1840 reviewers = relationship('PullRequestReviewers', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1841 cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1842 org_repo = relationship('Repository', primaryjoin='PullRequest.org_repo_id==Repository.repo_id') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1843 other_repo = relationship('Repository', primaryjoin='PullRequest.other_repo_id==Repository.repo_id') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1844 statuses = relationship('ChangesetStatus') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1845 comments = relationship('ChangesetComment', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1846 cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1847 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1848 def is_closed(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1849 return self.status == self.STATUS_CLOSED |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1850 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1851 def __json__(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1852 return dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1853 revisions=self.revisions |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1854 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1855 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1856 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1857 class PullRequestReviewers(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1858 __tablename__ = 'pull_request_reviewers' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1859 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1860 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1861 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1862 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1863 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1864 def __init__(self, user=None, pull_request=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1865 self.user = user |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1866 self.pull_request = pull_request |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1867 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1868 pull_requests_reviewers_id = Column('pull_requests_reviewers_id', Integer(), nullable=False, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1869 pull_request_id = Column("pull_request_id", Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1870 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1871 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1872 user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1873 pull_request = relationship('PullRequest') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1874 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1875 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1876 class Notification(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1877 __tablename__ = 'notifications' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1878 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1879 Index('notification_type_idx', 'type'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1880 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1881 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1882 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1883 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1884 TYPE_CHANGESET_COMMENT = u'cs_comment' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1885 TYPE_MESSAGE = u'message' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1886 TYPE_MENTION = u'mention' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1887 TYPE_REGISTRATION = u'registration' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1888 TYPE_PULL_REQUEST = u'pull_request' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1889 TYPE_PULL_REQUEST_COMMENT = u'pull_request_comment' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1890 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1891 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1892 subject = Column('subject', Unicode(512), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1893 body = Column('body', UnicodeText(50000), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1894 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1895 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1896 type_ = Column('type', Unicode(256)) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1897 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1898 created_by_user = relationship('User') |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1899 notifications_to_users = relationship('UserNotification', lazy='joined', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1900 cascade="all, delete, delete-orphan") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1901 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1902 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1903 def recipients(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1904 return [x.user for x in UserNotification.query()\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1905 .filter(UserNotification.notification == self)\ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1906 .order_by(UserNotification.user_id.asc()).all()] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1907 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1908 @classmethod |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1909 def create(cls, created_by, subject, body, recipients, type_=None): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1910 if type_ is None: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1911 type_ = Notification.TYPE_MESSAGE |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1912 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1913 notification = cls() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1914 notification.created_by_user = created_by |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1915 notification.subject = subject |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1916 notification.body = body |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1917 notification.type_ = type_ |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1918 notification.created_on = datetime.datetime.now() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1919 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1920 for u in recipients: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1921 assoc = UserNotification() |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1922 assoc.notification = notification |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1923 u.notifications.append(assoc) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1924 Session().add(notification) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1925 return notification |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1926 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1927 @property |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1928 def description(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1929 from rhodecode.model.notification import NotificationModel |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1930 return NotificationModel().make_description(self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1931 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1932 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1933 class UserNotification(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1934 __tablename__ = 'user_to_notification' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1935 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1936 UniqueConstraint('user_id', 'notification_id'), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1937 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1938 'mysql_charset': 'utf8'} |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1939 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1940 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1941 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1942 read = Column('read', Boolean, default=False) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1943 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1944 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1945 user = relationship('User', lazy="joined") |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1946 notification = relationship('Notification', lazy="joined", |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1947 order_by=lambda: Notification.created_on.desc(),) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1948 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1949 def mark_as_read(self): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1950 self.read = True |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1951 Session().add(self) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1952 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1953 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1954 class DbMigrateVersion(Base, BaseModel): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1955 __tablename__ = 'db_migrate_version' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1956 __table_args__ = ( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1957 {'extend_existing': True, 'mysql_engine': 'InnoDB', |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1958 'mysql_charset': 'utf8'}, |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1959 ) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1960 repository_id = Column('repository_id', String(250), primary_key=True) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1961 repository_path = Column('repository_path', Text) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3148
diff
changeset
|
1962 version = Column('version', Integer) |