annotate rhodecode/lib/dbmigrate/schema/db_1_3_0.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents fa6ba6727475
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1632
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 # This program is free software: you can redistribute it and/or modify
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 # it under the terms of the GNU General Public License as published by
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 # (at your option) any later version.
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 #
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # This program is distributed in the hope that it will be useful,
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 # GNU General Public License for more details.
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 #
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # You should have received a copy of the GNU General Public License
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1632
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
15 rhodecode.model.db_1_3_0
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
18 Database Models for RhodeCode <=1.3.X
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
20 :created_on: Apr 08, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
23 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
24
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
25 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
26
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
27
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
28 import os
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
29 import logging
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
30 import datetime
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
31 import traceback
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
32 from collections import defaultdict
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
33
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
34 from sqlalchemy import *
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
35 from sqlalchemy.ext.hybrid import hybrid_property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
36 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
37 from beaker.cache import cache_region, region_invalidate
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
38
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
39 from rhodecode.lib.vcs import get_backend
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
40 from rhodecode.lib.vcs.utils.helpers import get_scm
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
41 from rhodecode.lib.vcs.exceptions import VCSError
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
42 from rhodecode.lib.vcs.utils.lazy import LazyProperty
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
43
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
44 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
45 safe_unicode
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
46 from rhodecode.lib.compat import json
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
47 from rhodecode.lib.caching_query import FromCache
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
48
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
49 from rhodecode.model.meta import Base, Session
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
50 import hashlib
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
51
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
52
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
53 log = logging.getLogger(__name__)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
54
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
55 #==============================================================================
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
56 # BASE CLASSES
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
57 #==============================================================================
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
58
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
59 _hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
60
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
61
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
62 class ModelSerializer(json.JSONEncoder):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
63 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
64 Simple Serializer for JSON,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
65
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
66 usage::
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
67
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
68 to make object customized for serialization implement a __json__
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
69 method that will return a dict for serialization into json
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
70
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
71 example::
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
72
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
73 class Task(object):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
74
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
75 def __init__(self, name, value):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
76 self.name = name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
77 self.value = value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
78
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
79 def __json__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
80 return dict(name=self.name,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
81 value=self.value)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
82
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
83 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
84
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
85 def default(self, obj):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
86
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
87 if hasattr(obj, '__json__'):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
88 return obj.__json__()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
89 else:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
90 return json.JSONEncoder.default(self, obj)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
91
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
92
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
93 class BaseModel(object):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
94 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
95 Base Model for all classess
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
96 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
97
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
98 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
99 def _get_keys(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
100 """return column names for this model """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
101 return class_mapper(cls).c.keys()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
102
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
103 def get_dict(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
104 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
105 return dict with keys and values corresponding
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
106 to this model data """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
107
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
108 d = {}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
109 for k in self._get_keys():
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
110 d[k] = getattr(self, k)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
111
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
112 # also use __json__() if present to get additional fields
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
113 for k, val in getattr(self, '__json__', lambda: {})().iteritems():
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
114 d[k] = val
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
115 return d
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
116
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
117 def get_appstruct(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
118 """return list with keys and values tupples corresponding
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
119 to this model data """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
120
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
121 l = []
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
122 for k in self._get_keys():
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
123 l.append((k, getattr(self, k),))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
124 return l
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
125
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
126 def populate_obj(self, populate_dict):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
127 """populate model with data from given populate_dict"""
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
128
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
129 for k in self._get_keys():
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
130 if k in populate_dict:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
131 setattr(self, k, populate_dict[k])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
132
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
133 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
134 def query(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
135 return Session.query(cls)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
136
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
137 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
138 def get(cls, id_):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
139 if id_:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
140 return cls.query().get(id_)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
141
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
142 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
143 def getAll(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
144 return cls.query().all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
145
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
146 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
147 def delete(cls, id_):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
148 obj = cls.query().get(id_)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
149 Session.delete(obj)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
150
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
151 def __repr__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
152 if hasattr(self, '__unicode__'):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
153 # python repr needs to return str
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
154 return safe_str(self.__unicode__())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
155 return '<DB:%s>' % (self.__class__.__name__)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
156
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
157 class RhodeCodeSetting(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
158 __tablename__ = 'rhodecode_settings'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
159 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
160 UniqueConstraint('app_settings_name'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
161 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
162 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
163 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
164 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
165 app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
166 _app_settings_value = Column("app_settings_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
167
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
168 def __init__(self, k='', v=''):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
169 self.app_settings_name = k
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
170 self.app_settings_value = v
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
171
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
172 @validates('_app_settings_value')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
173 def validate_settings_value(self, key, val):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
174 assert type(val) == unicode
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
175 return val
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
176
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
177 @hybrid_property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
178 def app_settings_value(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
179 v = self._app_settings_value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
180 if self.app_settings_name == 'ldap_active':
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
181 v = str2bool(v)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
182 return v
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
183
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
184 @app_settings_value.setter
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
185 def app_settings_value(self, val):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
186 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
187 Setter that will always make sure we use unicode in app_settings_value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
188
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
189 :param val:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
190 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
191 self._app_settings_value = safe_unicode(val)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
192
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
193 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
194 return u"<%s('%s:%s')>" % (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
195 self.__class__.__name__,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
196 self.app_settings_name, self.app_settings_value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
197 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
198
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
199 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
200 def get_by_name(cls, ldap_key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
201 return cls.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
202 .filter(cls.app_settings_name == ldap_key).scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
203
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
204 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
205 def get_app_settings(cls, cache=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
206
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
207 ret = cls.query()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
208
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
209 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
210 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
211
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
212 if not ret:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
213 raise Exception('Could not get application settings !')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
214 settings = {}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
215 for each in ret:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
216 settings['rhodecode_' + each.app_settings_name] = \
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
217 each.app_settings_value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
218
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
219 return settings
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
220
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
221 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
222 def get_ldap_settings(cls, cache=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
223 ret = cls.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
224 .filter(cls.app_settings_name.startswith('ldap_')).all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
225 fd = {}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
226 for row in ret:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
227 fd.update({row.app_settings_name:row.app_settings_value})
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
228
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
229 return fd
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
230
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
231
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
232 class RhodeCodeUi(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
233 __tablename__ = 'rhodecode_ui'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
234 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
235 UniqueConstraint('ui_key'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
236 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
237 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
238 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
239
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
240 HOOK_UPDATE = 'changegroup.update'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
241 HOOK_REPO_SIZE = 'changegroup.repo_size'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
242 HOOK_PUSH = 'pretxnchangegroup.push_logger'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
243 HOOK_PULL = 'preoutgoing.pull_logger'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
244
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
245 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
246 ui_section = Column("ui_section", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
247 ui_key = Column("ui_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
248 ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
249 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
250
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
251 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
252 def get_by_key(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
253 return cls.query().filter(cls.ui_key == key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
254
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
255 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
256 def get_builtin_hooks(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
257 q = cls.query()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
258 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
259 cls.HOOK_REPO_SIZE,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
260 cls.HOOK_PUSH, cls.HOOK_PULL]))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
261 return q.all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
262
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
263 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
264 def get_custom_hooks(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
265 q = cls.query()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
266 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
267 cls.HOOK_REPO_SIZE,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
268 cls.HOOK_PUSH, cls.HOOK_PULL]))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
269 q = q.filter(cls.ui_section == 'hooks')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
270 return q.all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
271
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
272 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
273 def create_or_update_hook(cls, key, val):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
274 new_ui = cls.get_by_key(key).scalar() or cls()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
275 new_ui.ui_section = 'hooks'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
276 new_ui.ui_active = True
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
277 new_ui.ui_key = key
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
278 new_ui.ui_value = val
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
279
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
280 Session.add(new_ui)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
281
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
282
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
283 class User(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
284 __tablename__ = 'users'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
285 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
286 UniqueConstraint('username'), UniqueConstraint('email'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
287 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
288 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
289 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
290 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
291 username = Column("username", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
292 password = Column("password", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
293 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
294 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
295 name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
296 lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
297 _email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
298 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
299 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
300 api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
301
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
302 user_log = relationship('UserLog', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
303 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
304
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
305 repositories = relationship('Repository')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
306 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
307 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
308 repo_group_to_perm = relationship('UserRepoGroupToPerm', primaryjoin='UserRepoGroupToPerm.user_id==User.user_id', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
309
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
310 group_member = relationship('UserGroupMember', cascade='all')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
311
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
312 notifications = relationship('UserNotification', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
313 # notifications assigned to this user
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
314 user_created_notifications = relationship('Notification', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
315 # comments created by this user
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
316 user_comments = relationship('ChangesetComment', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
317
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
318 @hybrid_property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
319 def email(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
320 return self._email
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
321
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
322 @email.setter
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
323 def email(self, val):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
324 self._email = val.lower() if val else None
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
325
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
326 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
327 def full_name(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
328 return '%s %s' % (self.name, self.lastname)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
329
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
330 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
331 def full_name_or_username(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
332 return ('%s %s' % (self.name, self.lastname)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
333 if (self.name and self.lastname) else self.username)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
334
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
335 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
336 def full_contact(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
337 return '%s %s <%s>' % (self.name, self.lastname, self.email)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
338
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
339 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
340 def short_contact(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
341 return '%s %s' % (self.name, self.lastname)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
342
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
343 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
344 def is_admin(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
345 return self.admin
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
346
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
347 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
348 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
349 self.user_id, self.username)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
350
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
351 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
352 def get_by_username(cls, username, case_insensitive=False, cache=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
353 if case_insensitive:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
354 q = cls.query().filter(cls.username.ilike(username))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
355 else:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
356 q = cls.query().filter(cls.username == username)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
357
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
358 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
359 q = q.options(FromCache(
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
360 "sql_cache_short",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
361 "get_user_%s" % _hash_key(username)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
362 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
363 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
364 return q.scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
365
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
366 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
367 def get_by_api_key(cls, api_key, cache=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
368 q = cls.query().filter(cls.api_key == api_key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
369
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
370 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
371 q = q.options(FromCache("sql_cache_short",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
372 "get_api_key_%s" % api_key))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
373 return q.scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
374
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
375 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
376 def get_by_email(cls, email, case_insensitive=False, cache=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
377 if case_insensitive:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
378 q = cls.query().filter(cls.email.ilike(email))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
379 else:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
380 q = cls.query().filter(cls.email == email)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
381
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
382 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
383 q = q.options(FromCache("sql_cache_short",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
384 "get_api_key_%s" % email))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
385 return q.scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
386
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
387 def update_lastlogin(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
388 """Update user lastlogin"""
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
389 self.last_login = datetime.datetime.now()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
390 Session.add(self)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
391 log.debug('updated user %s lastlogin' % self.username)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
392
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
393 def __json__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
394 return dict(
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
395 user_id=self.user_id,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
396 first_name=self.name,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
397 last_name=self.lastname,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
398 email=self.email,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
399 full_name=self.full_name,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
400 full_name_or_username=self.full_name_or_username,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
401 short_contact=self.short_contact,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
402 full_contact=self.full_contact
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
403 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
404
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
405
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
406 class UserLog(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
407 __tablename__ = 'user_logs'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
408 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
409 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
410 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
411 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
412 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
413 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
414 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
415 repository_name = Column("repository_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
416 user_ip = Column("user_ip", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
417 action = Column("action", UnicodeText(length=1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
418 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
419
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
420 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
421 def action_as_day(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
422 return datetime.date(*self.action_date.timetuple()[:3])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
423
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
424 user = relationship('User')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
425 repository = relationship('Repository', cascade='')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
426
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
427
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
428 class UserGroup(Base, BaseModel):
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
429 __tablename__ = 'users_groups'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
430 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
431 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
432 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
433 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
434
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
435 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
436 users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
437 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
438
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
439 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
440 users_group_to_perm = relationship('UserGroupToPerm', cascade='all')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
441 users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
442
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
443 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
444 return u'<userGroup(%s)>' % (self.users_group_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
445
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
446 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
447 def get_by_group_name(cls, group_name, cache=False,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
448 case_insensitive=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
449 if case_insensitive:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
450 q = cls.query().filter(cls.users_group_name.ilike(group_name))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
451 else:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
452 q = cls.query().filter(cls.users_group_name == group_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
453 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
454 q = q.options(FromCache(
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
455 "sql_cache_short",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
456 "get_user_%s" % _hash_key(group_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
457 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
458 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
459 return q.scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
460
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
461 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
462 def get(cls, users_group_id, cache=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
463 users_group = cls.query()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
464 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
465 users_group = users_group.options(FromCache("sql_cache_short",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
466 "get_users_group_%s" % users_group_id))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
467 return users_group.get(users_group_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
468
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
469
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
470 class UserGroupMember(Base, BaseModel):
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
471 __tablename__ = 'users_groups_members'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
472 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
473 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
474 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
475 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
476
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
477 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
478 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
479 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
480
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
481 user = relationship('User', lazy='joined')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
482 users_group = relationship('UserGroup')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
483
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
484 def __init__(self, gr_id='', u_id=''):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
485 self.users_group_id = gr_id
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
486 self.user_id = u_id
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
487
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
488
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
489 class Repository(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
490 __tablename__ = 'repositories'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
491 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
492 UniqueConstraint('repo_name'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
493 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
494 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
495 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
496
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
497 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
498 repo_name = Column("repo_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
499 clone_uri = Column("clone_uri", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
500 repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
501 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
502 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
503 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
504 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
505 description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
506 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
507
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
508 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
509 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
510
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
511 user = relationship('User')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
512 fork = relationship('Repository', remote_side=repo_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
513 group = relationship('RepoGroup')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
514 repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
515 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
516 stats = relationship('Statistics', cascade='all', uselist=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
517
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
518 followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
519
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
520 logs = relationship('UserLog')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
521
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
522 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
523 return u"<%s('%s:%s')>" % (self.__class__.__name__,self.repo_id,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
524 self.repo_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
525
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
526 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
527 def url_sep(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
528 return '/'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
529
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
530 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
531 def get_by_repo_name(cls, repo_name):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
532 q = Session.query(cls).filter(cls.repo_name == repo_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
533 q = q.options(joinedload(Repository.fork))\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
534 .options(joinedload(Repository.user))\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
535 .options(joinedload(Repository.group))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
536 return q.scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
537
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
538 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
539 def get_repo_forks(cls, repo_id):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
540 return cls.query().filter(Repository.fork_id == repo_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
541
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
542 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
543 def base_path(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
544 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
545 Returns base path when all repos are stored
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
546
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
547 :param cls:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
548 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
549 q = Session.query(RhodeCodeUi)\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
550 .filter(RhodeCodeUi.ui_key == cls.url_sep())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
551 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
552 return q.one().ui_value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
553
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
554 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
555 def just_name(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
556 return self.repo_name.split(Repository.url_sep())[-1]
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
557
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
558 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
559 def groups_with_parents(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
560 groups = []
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
561 if self.group is None:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
562 return groups
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
563
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
564 cur_gr = self.group
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
565 groups.insert(0, cur_gr)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
566 while 1:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
567 gr = getattr(cur_gr, 'parent_group', None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
568 cur_gr = cur_gr.parent_group
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
569 if gr is None:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
570 break
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
571 groups.insert(0, gr)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
572
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
573 return groups
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
574
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
575 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
576 def groups_and_repo(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
577 return self.groups_with_parents, self.just_name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
578
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
579 @LazyProperty
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
580 def repo_path(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
581 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
582 Returns base full path for that repository means where it actually
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
583 exists on a filesystem
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
584 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
585 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
586 Repository.url_sep())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
587 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
588 return q.one().ui_value
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
589
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
590 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
591 def repo_full_path(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
592 p = [self.repo_path]
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
593 # we need to split the name by / since this is how we store the
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
594 # names in the database, but that eventually needs to be converted
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
595 # into a valid system path
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
596 p += self.repo_name.split(Repository.url_sep())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
597 return os.path.join(*p)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
598
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
599 def get_new_name(self, repo_name):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
600 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
601 returns new full repository name based on assigned group and new new
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
602
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
603 :param group_name:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
604 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
605 path_prefix = self.group.full_path_splitted if self.group else []
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
606 return Repository.url_sep().join(path_prefix + [repo_name])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
607
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
608 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
609 def _ui(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
610 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
611 Creates an db based ui object for this repository
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
612 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
613 from mercurial import ui
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
614 from mercurial import config
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
615 baseui = ui.ui()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
616
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
617 #clean the baseui object
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
618 baseui._ocfg = config.config()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
619 baseui._ucfg = config.config()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
620 baseui._tcfg = config.config()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
621
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
622 ret = RhodeCodeUi.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
623 .options(FromCache("sql_cache_short", "repository_repo_ui")).all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
624
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
625 hg_ui = ret
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
626 for ui_ in hg_ui:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
627 if ui_.ui_active:
3133
95b4242a275e logging: make 'settings ui from db' look more like Mercurial ini file notation
Mads Kiilerich <madski@unity3d.com>
parents: 2815
diff changeset
628 log.debug('settings ui from db: [%s] %s=%s', ui_.ui_section,
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
629 ui_.ui_key, ui_.ui_value)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
630 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
631
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
632 return baseui
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
633
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
634 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
635 def is_valid(cls, repo_name):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
636 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
637 returns True if given repo name is a valid filesystem repository
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
638
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
639 :param cls:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
640 :param repo_name:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
641 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
642 from rhodecode.lib.utils import is_valid_repo
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
643
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
644 return is_valid_repo(repo_name, cls.base_path())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
645
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
646 #==========================================================================
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
647 # SCM PROPERTIES
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
648 #==========================================================================
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
649
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
650 def get_changeset(self, rev):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
651 return get_changeset_safe(self.scm_instance, rev)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
652
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
653 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
654 def tip(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
655 return self.get_changeset('tip')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
656
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
657 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
658 def author(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
659 return self.tip.author
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
660
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
661 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
662 def last_change(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
663 return self.scm_instance.last_change
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
664
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
665 def comments(self, revisions=None):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
666 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
667 Returns comments for this repository grouped by revisions
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
668
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
669 :param revisions: filter query by revisions only
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
670 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
671 cmts = ChangesetComment.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
672 .filter(ChangesetComment.repo == self)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
673 if revisions:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
674 cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
675 grouped = defaultdict(list)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
676 for cmt in cmts.all():
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
677 grouped[cmt.revision].append(cmt)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
678 return grouped
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
679
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
680 #==========================================================================
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
681 # SCM CACHE INSTANCE
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
682 #==========================================================================
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
683
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
684 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
685 def invalidate(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
686 return CacheInvalidation.invalidate(self.repo_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
687
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
688 def set_invalidate(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
689 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
690 set a cache for invalidation for this instance
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
691 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
692 CacheInvalidation.set_invalidate(self.repo_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
693
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
694 @LazyProperty
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
695 def scm_instance(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
696 return self.__get_instance()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
697
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
698 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
699 def scm_instance_cached(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
700 @cache_region('long_term')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
701 def _c(repo_name):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
702 return self.__get_instance()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
703 rn = self.repo_name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
704 log.debug('Getting cached instance of repo')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
705 inv = self.invalidate
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
706 if inv is not None:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
707 region_invalidate(_c, None, rn)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
708 # update our cache
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
709 CacheInvalidation.set_valid(inv.cache_key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
710 return _c(rn)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
711
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
712 def __get_instance(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
713 repo_full_path = self.repo_full_path
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
714 try:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
715 alias = get_scm(repo_full_path)[0]
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
716 log.debug('Creating instance of %s repository' % alias)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
717 backend = get_backend(alias)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
718 except VCSError:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
719 log.error(traceback.format_exc())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
720 log.error('Perhaps this repository is in db and not in '
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
721 'filesystem run rescan repositories with '
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
722 '"destroy old data " option from admin panel')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
723 return
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
724
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
725 if alias == 'hg':
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
726
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
727 repo = backend(safe_str(repo_full_path), create=False,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
728 baseui=self._ui)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
729 # skip hidden web repository
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
730 if repo._get_hidden():
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
731 return
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
732 else:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
733 repo = backend(repo_full_path, create=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
734
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
735 return repo
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
736
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
737
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
738 class RepoGroup(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
739 __tablename__ = 'groups'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
740 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
741 UniqueConstraint('group_name', 'group_parent_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
742 CheckConstraint('group_id != group_parent_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
743 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
744 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
745 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
746 __mapper_args__ = {'order_by': 'group_name'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
747
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
748 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
749 group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
750 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
751 group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
752
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
753 repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
754 users_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
755
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
756 parent_group = relationship('RepoGroup', remote_side=group_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
757
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
758 def __init__(self, group_name='', parent_group=None):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
759 self.group_name = group_name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
760 self.parent_group = parent_group
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
761
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
762 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
763 return u"<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
764 self.group_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
765
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
766 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
767 def groups_choices(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
768 from webhelpers.html import literal as _literal
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
769 repo_groups = [('', '')]
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
770 sep = ' &raquo; '
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
771 _name = lambda k: _literal(sep.join(k))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
772
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
773 repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
774 for x in cls.query().all()])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
775
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
776 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
777 return repo_groups
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
778
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
779 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
780 def url_sep(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
781 return '/'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
782
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
783 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
784 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
785 if case_insensitive:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
786 gr = cls.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
787 .filter(cls.group_name.ilike(group_name))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
788 else:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
789 gr = cls.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
790 .filter(cls.group_name == group_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
791 if cache:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
792 gr = gr.options(FromCache(
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
793 "sql_cache_short",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
794 "get_group_%s" % _hash_key(group_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
795 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
796 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
797 return gr.scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
798
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
799 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
800 def parents(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
801 parents_recursion_limit = 5
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
802 groups = []
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
803 if self.parent_group is None:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
804 return groups
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
805 cur_gr = self.parent_group
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
806 groups.insert(0, cur_gr)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
807 cnt = 0
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
808 while 1:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
809 cnt += 1
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
810 gr = getattr(cur_gr, 'parent_group', None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
811 cur_gr = cur_gr.parent_group
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
812 if gr is None:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
813 break
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
814 if cnt == parents_recursion_limit:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
815 # this will prevent accidental infinit loops
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
816 log.error('group nested more than %s' %
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
817 parents_recursion_limit)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
818 break
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
819
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
820 groups.insert(0, gr)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
821 return groups
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
822
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
823 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
824 def children(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
825 return RepoGroup.query().filter(RepoGroup.parent_group == self)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
826
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
827 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
828 def name(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
829 return self.group_name.split(RepoGroup.url_sep())[-1]
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
830
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
831 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
832 def full_path(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
833 return self.group_name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
834
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
835 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
836 def full_path_splitted(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
837 return self.group_name.split(RepoGroup.url_sep())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
838
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
839 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
840 def repositories(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
841 return Repository.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
842 .filter(Repository.group == self)\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
843 .order_by(Repository.repo_name)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
844
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
845 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
846 def repositories_recursive_count(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
847 cnt = self.repositories.count()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
848
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
849 def children_count(group):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
850 cnt = 0
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
851 for child in group.children:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
852 cnt += child.repositories.count()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
853 cnt += children_count(child)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
854 return cnt
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
855
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
856 return cnt + children_count(self)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
857
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
858 def get_new_name(self, group_name):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
859 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
860 returns new full group name based on parent and new name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
861
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
862 :param group_name:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
863 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
864 path_prefix = (self.parent_group.full_path_splitted if
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
865 self.parent_group else [])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
866 return RepoGroup.url_sep().join(path_prefix + [group_name])
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
867
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
868
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
869 class Permission(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
870 __tablename__ = 'permissions'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
871 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
872 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
873 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
874 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
875 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
876 permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
877 permission_longname = Column("permission_longname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
878
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
879 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
880 return u"<%s('%s:%s')>" % (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
881 self.__class__.__name__, self.permission_id, self.permission_name
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
882 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
883
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
884 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
885 def get_by_key(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
886 return cls.query().filter(cls.permission_name == key).scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
887
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
888 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
889 def get_default_perms(cls, default_user_id):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
890 q = Session.query(UserRepoToPerm, Repository, cls)\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
891 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
892 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
893 .filter(UserRepoToPerm.user_id == default_user_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
894
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
895 return q.all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
896
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
897 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
898 def get_default_group_perms(cls, default_user_id):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
899 q = Session.query(UserRepoGroupToPerm, RepoGroup, cls)\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
900 .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
901 .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
902 .filter(UserRepoGroupToPerm.user_id == default_user_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
903
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
904 return q.all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
905
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
906
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
907 class UserRepoToPerm(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
908 __tablename__ = 'repo_to_perm'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
909 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
910 UniqueConstraint('user_id', 'repository_id', 'permission_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
911 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
912 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
913 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
914 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
915 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
916 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
917 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
918
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
919 user = relationship('User')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
920 repository = relationship('Repository')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
921 permission = relationship('Permission')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
922
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
923 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
924 def create(cls, user, repository, permission):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
925 n = cls()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
926 n.user = user
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
927 n.repository = repository
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
928 n.permission = permission
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
929 Session.add(n)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
930 return n
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
931
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
932 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
933 return u'<user:%s => %s >' % (self.user, self.repository)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
934
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
935
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
936 class UserToPerm(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
937 __tablename__ = 'user_to_perm'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
938 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
939 UniqueConstraint('user_id', 'permission_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
940 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
941 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
942 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
943 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
944 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
945 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
946
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
947 user = relationship('User')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
948 permission = relationship('Permission', lazy='joined')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
949
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
950
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
951 class UserGroupRepoToPerm(Base, BaseModel):
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
952 __tablename__ = 'users_group_repo_to_perm'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
953 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
954 UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
955 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
956 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
957 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
958 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
959 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
960 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
961 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
962
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
963 users_group = relationship('UserGroup')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
964 permission = relationship('Permission')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
965 repository = relationship('Repository')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
966
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
967 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
968 def create(cls, users_group, repository, permission):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
969 n = cls()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
970 n.users_group = users_group
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
971 n.repository = repository
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
972 n.permission = permission
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
973 Session.add(n)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
974 return n
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
975
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
976 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
977 return u'<userGroup:%s => %s >' % (self.users_group, self.repository)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
978
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
979
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
980 class UserGroupToPerm(Base, BaseModel):
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
981 __tablename__ = 'users_group_to_perm'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
982 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
983 UniqueConstraint('users_group_id', 'permission_id',),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
984 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
985 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
986 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
987 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
988 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
989 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
990
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
991 users_group = relationship('UserGroup')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
992 permission = relationship('Permission')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
993
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
994
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
995 class UserRepoGroupToPerm(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
996 __tablename__ = 'user_repo_group_to_perm'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
997 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
998 UniqueConstraint('user_id', 'group_id', 'permission_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
999 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1000 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1001 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1002
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1003 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1004 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1005 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1006 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1007
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1008 user = relationship('User')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1009 group = relationship('RepoGroup')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1010 permission = relationship('Permission')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1011
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1012
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
1013 class UserGroupRepoGroupToPerm(Base, BaseModel):
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1014 __tablename__ = 'users_group_repo_group_to_perm'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1015 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1016 UniqueConstraint('users_group_id', 'group_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1017 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1018 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1019 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1020
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1021 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)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1022 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1023 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1024 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1025
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
1026 users_group = relationship('UserGroup')
2214
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1027 permission = relationship('Permission')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1028 group = relationship('RepoGroup')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1029
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1030
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1031 class Statistics(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1032 __tablename__ = 'statistics'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1033 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1034 UniqueConstraint('repository_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1035 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1036 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1037 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1038 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1039 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1040 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1041 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1042 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1043 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1044
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1045 repository = relationship('Repository', single_parent=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1046
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1047
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1048 class UserFollowing(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1049 __tablename__ = 'user_followings'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1050 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1051 UniqueConstraint('user_id', 'follows_repository_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1052 UniqueConstraint('user_id', 'follows_user_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1053 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1054 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1055 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1056
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1057 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1058 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1059 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1060 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1061 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1062
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1063 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1064
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1065 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1066 follows_repository = relationship('Repository', order_by='Repository.repo_name')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1067
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1068 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1069 def get_repo_followers(cls, repo_id):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1070 return cls.query().filter(cls.follows_repo_id == repo_id)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1071
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1072
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1073 class CacheInvalidation(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1074 __tablename__ = 'cache_invalidation'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1075 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1076 UniqueConstraint('cache_key'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1077 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1078 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1079 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1080 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1081 cache_key = Column("cache_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1082 cache_args = Column("cache_args", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1083 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1084
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1085 def __init__(self, cache_key, cache_args=''):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1086 self.cache_key = cache_key
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1087 self.cache_args = cache_args
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1088 self.cache_active = False
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1089
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1090 def __unicode__(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1091 return u"<%s('%s:%s')>" % (self.__class__.__name__,
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1092 self.cache_id, self.cache_key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1093 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1094 def clear_cache(cls):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1095 cls.query().delete()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1096
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1097 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1098 def _get_key(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1099 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1100 Wrapper for generating a key, together with a prefix
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1101
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1102 :param key:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1103 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1104 import rhodecode
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1105 prefix = ''
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1106 iid = rhodecode.CONFIG.get('instance_id')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1107 if iid:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1108 prefix = iid
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1109 return "%s%s" % (prefix, key), prefix, key.rstrip('_README')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1110
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1111 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1112 def get_by_key(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1113 return cls.query().filter(cls.cache_key == key).scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1114
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1115 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1116 def _get_or_create_key(cls, key, prefix, org_key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1117 inv_obj = Session.query(cls).filter(cls.cache_key == key).scalar()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1118 if not inv_obj:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1119 try:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1120 inv_obj = CacheInvalidation(key, org_key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1121 Session.add(inv_obj)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1122 Session.commit()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1123 except Exception:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1124 log.error(traceback.format_exc())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1125 Session.rollback()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1126 return inv_obj
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1127
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1128 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1129 def invalidate(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1130 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1131 Returns Invalidation object if this given key should be invalidated
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1132 None otherwise. `cache_active = False` means that this cache
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1133 state is not valid and needs to be invalidated
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1134
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1135 :param key:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1136 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1137
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1138 key, _prefix, _org_key = cls._get_key(key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1139 inv = cls._get_or_create_key(key, _prefix, _org_key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1140
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1141 if inv and inv.cache_active is False:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1142 return inv
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1143
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1144 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1145 def set_invalidate(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1146 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1147 Mark this Cache key for invalidation
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1148
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1149 :param key:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1150 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1151
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1152 key, _prefix, _org_key = cls._get_key(key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1153 inv_objs = Session.query(cls).filter(cls.cache_args == _org_key).all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1154 log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1155 _org_key))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1156 try:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1157 for inv_obj in inv_objs:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1158 if inv_obj:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1159 inv_obj.cache_active = False
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1160
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1161 Session.add(inv_obj)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1162 Session.commit()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1163 except Exception:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1164 log.error(traceback.format_exc())
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1165 Session.rollback()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1166
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1167 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1168 def set_valid(cls, key):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1169 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1170 Mark this cache key as active and currently cached
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1171
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1172 :param key:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1173 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1174 inv_obj = cls.get_by_key(key)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1175 inv_obj.cache_active = True
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1176 Session.add(inv_obj)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1177 Session.commit()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1178
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1179
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1180 class ChangesetComment(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1181 __tablename__ = 'changeset_comments'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1182 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1183 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1184 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1185 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1186 comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1187 repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1188 revision = Column('revision', String(40), nullable=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1189 line_no = Column('line_no', Unicode(10), nullable=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1190 f_path = Column('f_path', Unicode(1000), nullable=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1191 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1192 text = Column('text', Unicode(25000), nullable=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1193 modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1194
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1195 author = relationship('User', lazy='joined')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1196 repo = relationship('Repository')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1197
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1198 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1199 def get_users(cls, revision):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1200 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1201 Returns user associated with this changesetComment. ie those
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1202 who actually commented
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1203
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1204 :param cls:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1205 :param revision:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1206 """
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1207 return Session.query(User)\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1208 .filter(cls.revision == revision)\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1209 .join(ChangesetComment.author).all()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1210
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1211
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1212 class Notification(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1213 __tablename__ = 'notifications'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1214 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1215 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1216 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1217 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1218
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1219 TYPE_CHANGESET_COMMENT = u'cs_comment'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1220 TYPE_MESSAGE = u'message'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1221 TYPE_MENTION = u'mention'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1222 TYPE_REGISTRATION = u'registration'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1223
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1224 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1225 subject = Column('subject', Unicode(512), nullable=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1226 body = Column('body', Unicode(50000), nullable=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1227 created_by = Column("created_by", Integer(), ForeignKey('users.user_id'), nullable=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1228 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1229 type_ = Column('type', Unicode(256))
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1230
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1231 created_by_user = relationship('User')
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1232 notifications_to_users = relationship('UserNotification', lazy='joined',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1233 cascade="all, delete, delete-orphan")
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1234
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1235 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1236 def recipients(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1237 return [x.user for x in UserNotification.query()\
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1238 .filter(UserNotification.notification == self).all()]
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1239
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1240 @classmethod
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1241 def create(cls, created_by, subject, body, recipients, type_=None):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1242 if type_ is None:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1243 type_ = Notification.TYPE_MESSAGE
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1244
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1245 notification = cls()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1246 notification.created_by_user = created_by
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1247 notification.subject = subject
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1248 notification.body = body
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1249 notification.type_ = type_
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1250 notification.created_on = datetime.datetime.now()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1251
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1252 for u in recipients:
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1253 assoc = UserNotification()
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1254 assoc.notification = notification
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1255 u.notifications.append(assoc)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1256 Session.add(notification)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1257 return notification
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1258
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1259 @property
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1260 def description(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1261 from rhodecode.model.notification import NotificationModel
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1262 return NotificationModel().make_description(self)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1263
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1264
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1265 class UserNotification(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1266 __tablename__ = 'user_to_notification'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1267 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1268 UniqueConstraint('user_id', 'notification_id'),
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1269 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1270 'mysql_charset': 'utf8'}
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1271 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1272 user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1273 notification_id = Column("notification_id", Integer(), ForeignKey('notifications.notification_id'), primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1274 read = Column('read', Boolean, default=False)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1275 sent_on = Column('sent_on', DateTime(timezone=False), nullable=True, unique=None)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1276
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1277 user = relationship('User', lazy="joined")
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1278 notification = relationship('Notification', lazy="joined",
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1279 order_by=lambda: Notification.created_on.desc(),)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1280
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1281 def mark_as_read(self):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1282 self.read = True
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1283 Session.add(self)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1284
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1285
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1286 class DbMigrateVersion(Base, BaseModel):
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1287 __tablename__ = 'db_migrate_version'
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1288 __table_args__ = (
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1289 {'extend_existing': True, 'mysql_engine':'InnoDB',
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1290 'mysql_charset': 'utf8'},
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1291 )
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1292 repository_id = Column('repository_id', String(250), primary_key=True)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1293 repository_path = Column('repository_path', Text)
2fd474e63177 Starting RhodeCode 1.4 Branch
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
1294 version = Column('version', Integer)
2765
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1295
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1296 ## this is migration from 1_4_0, but now it's here to overcome a problem of
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1297 ## attaching a FK to this from 1_3_0 !
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1298
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1299
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1300 class PullRequest(Base, BaseModel):
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1301 __tablename__ = 'pull_requests'
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1302 __table_args__ = (
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1303 {'extend_existing': True, 'mysql_engine': 'InnoDB',
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1304 'mysql_charset': 'utf8'},
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1305 )
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1306
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1307 STATUS_NEW = u'new'
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1308 STATUS_OPEN = u'open'
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1309 STATUS_CLOSED = u'closed'
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1310
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1311 pull_request_id = Column('pull_request_id', Integer(), nullable=False, primary_key=True)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1312 title = Column('title', Unicode(256), nullable=True)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1313 description = Column('description', UnicodeText(10240), nullable=True)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1314 status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1315 created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1316 updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1317 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1318 _revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1319 org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1320 org_ref = Column('org_ref', Unicode(256), nullable=False)
186b1cf7f759 Step6a for migrations from 1.3.6
Marcin Kuzminski <marcin@python-works.com>
parents: 2214
diff changeset
1321 other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
2815
acc05c33cc0c White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2765
diff changeset
1322 other_ref = Column('other_ref', Unicode(256), nullable=False)