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