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