annotate rhodecode/lib/dbmigrate/schema/db_1_2_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
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 # This program is free software: you can redistribute it and/or modify
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 # it under the terms of the GNU General Public License as published by
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 # (at your option) any later version.
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 #
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # This program is distributed in the hope that it will be useful,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 # GNU General Public License for more details.
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 #
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # You should have received a copy of the GNU General Public License
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
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_2_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.2.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 """
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import os
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import logging
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import datetime
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 import traceback
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from datetime import date
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from sqlalchemy import *
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from sqlalchemy.ext.hybrid import hybrid_property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 from beaker.cache import cache_region, region_invalidate
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
37 from rhodecode.lib.vcs import get_backend
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
38 from rhodecode.lib.vcs.utils.helpers import get_scm
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
39 from rhodecode.lib.vcs.exceptions import VCSError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
40 from rhodecode.lib.vcs.utils.lazy import LazyProperty
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
42 from rhodecode.lib.utils2 import str2bool, safe_str, get_changeset_safe, \
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 generate_api_key, safe_unicode
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
44 from rhodecode.lib.exceptions import UserGroupsAssignedException
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 from rhodecode.lib.compat import json
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 from rhodecode.model.meta import Base, Session
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1631
diff changeset
48 from rhodecode.lib.caching_query import FromCache
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 log = logging.getLogger(__name__)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 #==============================================================================
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 # BASE CLASSES
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 #==============================================================================
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 class ModelSerializer(json.JSONEncoder):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 Simple Serializer for JSON,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 usage::
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 to make object customized for serialization implement a __json__
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 method that will return a dict for serialization into json
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 example::
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 class Task(object):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 def __init__(self, name, value):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 self.name = name
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 self.value = value
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 def __json__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 return dict(name=self.name,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 value=self.value)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 def default(self, obj):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 if hasattr(obj, '__json__'):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 return obj.__json__()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 else:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 return json.JSONEncoder.default(self, obj)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 class BaseModel(object):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 """Base Model for all classess
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 def _get_keys(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 """return column names for this model """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 return class_mapper(cls).c.keys()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 def get_dict(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 """return dict with keys and values corresponding
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 to this model data """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 d = {}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 for k in self._get_keys():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 d[k] = getattr(self, k)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 return d
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 def get_appstruct(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 """return list with keys and values tupples corresponding
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 to this model data """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 l = []
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 for k in self._get_keys():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 l.append((k, getattr(self, k),))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 return l
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 def populate_obj(self, populate_dict):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 """populate model with data from given populate_dict"""
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 for k in self._get_keys():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 if k in populate_dict:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 setattr(self, k, populate_dict[k])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 def query(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 return Session.query(cls)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 def get(cls, id_):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 if id_:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 return cls.query().get(id_)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 def getAll(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 return cls.query().all()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 def delete(cls, id_):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 obj = cls.query().get(id_)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 Session.delete(obj)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 class RhodeCodeSetting(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 __tablename__ = 'rhodecode_settings'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 __table_args__ = (UniqueConstraint('app_settings_name'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 _app_settings_value = Column("app_settings_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 def __init__(self, k='', v=''):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 self.app_settings_name = k
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 self.app_settings_value = v
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 @validates('_app_settings_value')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 def validate_settings_value(self, key, val):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 assert type(val) == unicode
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 return val
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 @hybrid_property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 def app_settings_value(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 v = self._app_settings_value
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 if v == 'ldap_active':
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163 v = str2bool(v)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 return v
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 @app_settings_value.setter
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 def app_settings_value(self, val):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 Setter that will always make sure we use unicode in app_settings_value
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 :param val:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 self._app_settings_value = safe_unicode(val)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 return "<%s('%s:%s')>" % (self.__class__.__name__,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 self.app_settings_name, self.app_settings_value)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 def get_by_name(cls, ldap_key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 return cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 .filter(cls.app_settings_name == ldap_key).scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 def get_app_settings(cls, cache=False):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 ret = cls.query()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 if cache:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 if not ret:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 raise Exception('Could not get application settings !')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 settings = {}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 for each in ret:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 settings['rhodecode_' + each.app_settings_name] = \
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 each.app_settings_value
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 return settings
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 def get_ldap_settings(cls, cache=False):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 ret = cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205 .filter(cls.app_settings_name.startswith('ldap_')).all()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 fd = {}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 for row in ret:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208 fd.update({row.app_settings_name:row.app_settings_value})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 return fd
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 class RhodeCodeUi(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 __tablename__ = 'rhodecode_ui'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215 __table_args__ = (UniqueConstraint('ui_key'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 HOOK_UPDATE = 'changegroup.update'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218 HOOK_REPO_SIZE = 'changegroup.repo_size'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 HOOK_PUSH = 'pretxnchangegroup.push_logger'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 HOOK_PULL = 'preoutgoing.pull_logger'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 ui_section = Column("ui_section", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 ui_key = Column("ui_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 ui_value = Column("ui_value", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 def get_by_key(cls, key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 return cls.query().filter(cls.ui_key == key)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235 def get_builtin_hooks(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 q = cls.query()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238 cls.HOOK_REPO_SIZE,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
239 cls.HOOK_PUSH, cls.HOOK_PULL]))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240 return q.all()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
241
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
242 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243 def get_custom_hooks(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244 q = cls.query()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245 q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
246 cls.HOOK_REPO_SIZE,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
247 cls.HOOK_PUSH, cls.HOOK_PULL]))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 q = q.filter(cls.ui_section == 'hooks')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249 return q.all()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
251 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
252 def create_or_update_hook(cls, key, val):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
253 new_ui = cls.get_by_key(key).scalar() or cls()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
254 new_ui.ui_section = 'hooks'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 new_ui.ui_active = True
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256 new_ui.ui_key = key
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
257 new_ui.ui_value = val
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
258
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
259 Session.add(new_ui)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
260 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
261
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
262
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
263 class User(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264 __tablename__ = 'users'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
265 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 username = Column("username", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
268 password = Column("password", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
269 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
270 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
271 name = Column("name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
272 lastname = Column("lastname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 email = Column("email", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
275 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276 api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278 user_log = relationship('UserLog', cascade='all')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 repositories = relationship('Repository')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
283 repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
285 group_member = relationship('UserGroupMember', cascade='all')
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288 def full_contact(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
289 return '%s %s <%s>' % (self.name, self.lastname, self.email)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
290
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
291 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
292 def short_contact(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
293 return '%s %s' % (self.name, self.lastname)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
294
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
295 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
296 def is_admin(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
297 return self.admin
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
298
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
299 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
300 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
301 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 self.user_id, self.username)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 return self.__class__.__name__
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
306 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
307 def get_by_username(cls, username, case_insensitive=False):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
308 if case_insensitive:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
309 return Session.query(cls).filter(cls.username.ilike(username)).scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
310 else:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
311 return Session.query(cls).filter(cls.username == username).scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
312
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
313 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
314 def get_by_api_key(cls, api_key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315 return cls.query().filter(cls.api_key == api_key).one()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
316
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
317 def update_lastlogin(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
318 """Update user lastlogin"""
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
319
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
320 self.last_login = datetime.datetime.now()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
321 Session.add(self)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
322 Session.commit()
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
323 log.debug('updated user %s lastlogin' % self.username)
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
326 def create(cls, form_data):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
327 from rhodecode.lib.auth import get_crypt_password
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
328
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
329 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
330 new_user = cls()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331 for k, v in form_data.items():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 if k == 'password':
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
333 v = get_crypt_password(v)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
334 setattr(new_user, k, v)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
335
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
336 new_user.api_key = generate_api_key(form_data['username'])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
337 Session.add(new_user)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
338 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
339 return new_user
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
340 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
341 log.error(traceback.format_exc())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
342 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
343 raise
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
344
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
345 class UserLog(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
346 __tablename__ = 'user_logs'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
347 __table_args__ = {'extend_existing':True}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
348 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
349 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
350 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
351 repository_name = Column("repository_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
352 user_ip = Column("user_ip", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
353 action = Column("action", UnicodeText(length=1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
354 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
355
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
356 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
357 def action_as_day(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
358 return date(*self.action_date.timetuple()[:3])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
359
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
360 user = relationship('User')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
361 repository = relationship('Repository')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
362
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
363
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
364 class UserGroup(Base, BaseModel):
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
365 __tablename__ = 'users_groups'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
366 __table_args__ = {'extend_existing':True}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
367
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
368 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
369 users_group_name = Column("users_group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
370 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
371
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
372 members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
373
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
374 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
375 return '<userGroup(%s)>' % (self.users_group_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
376
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
377 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
378 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
379 if case_insensitive:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
380 gr = cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
381 .filter(cls.users_group_name.ilike(group_name))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
382 else:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
383 gr = cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
384 .filter(cls.users_group_name == group_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
385 if cache:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
386 gr = gr.options(FromCache("sql_cache_short",
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
387 "get_user_%s" % group_name))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
388 return gr.scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
389
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
390
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
391 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
392 def get(cls, users_group_id, cache=False):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
393 users_group = cls.query()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
394 if cache:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
395 users_group = users_group.options(FromCache("sql_cache_short",
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
396 "get_users_group_%s" % users_group_id))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
397 return users_group.get(users_group_id)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
398
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
399 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
400 def create(cls, form_data):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
401 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
402 new_users_group = cls()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
403 for k, v in form_data.items():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
404 setattr(new_users_group, k, v)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
405
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
406 Session.add(new_users_group)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
407 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
408 return new_users_group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
409 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
410 log.error(traceback.format_exc())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
411 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
412 raise
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
413
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
414 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
415 def update(cls, users_group_id, form_data):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
416
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
417 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
418 users_group = cls.get(users_group_id, cache=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
419
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
420 for k, v in form_data.items():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
421 if k == 'users_group_members':
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
422 users_group.members = []
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
423 Session.flush()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
424 members_list = []
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
425 if v:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
426 v = [v] if isinstance(v, basestring) else v
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
427 for u_id in set(v):
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
428 member = UserGroupMember(users_group_id, u_id)
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
429 members_list.append(member)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
430 setattr(users_group, 'members', members_list)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
431 setattr(users_group, k, v)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
432
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
433 Session.add(users_group)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
434 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
435 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
436 log.error(traceback.format_exc())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
437 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
438 raise
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
439
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
440 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
441 def delete(cls, users_group_id):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
442 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
443
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
444 # check if this group is not assigned to repo
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
445 assigned_groups = UserGroupRepoToPerm.query()\
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
446 .filter(UserGroupRepoToPerm.users_group_id ==
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
447 users_group_id).all()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
448
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
449 if assigned_groups:
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
450 raise UserGroupsAssignedException('RepoGroup assigned to %s' %
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
451 assigned_groups)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
452
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
453 users_group = cls.get(users_group_id, cache=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
454 Session.delete(users_group)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
455 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
456 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
457 log.error(traceback.format_exc())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
458 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
459 raise
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
460
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
461 class UserGroupMember(Base, BaseModel):
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
462 __tablename__ = 'users_groups_members'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
463 __table_args__ = {'extend_existing':True}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
464
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
465 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
466 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
467 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
468
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
469 user = relationship('User', lazy='joined')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
470 users_group = relationship('UserGroup')
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
471
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
472 def __init__(self, gr_id='', u_id=''):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
473 self.users_group_id = gr_id
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
474 self.user_id = u_id
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
475
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
476 @staticmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
477 def add_user_to_group(group, user):
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
478 ugm = UserGroupMember()
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
479 ugm.users_group = group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
480 ugm.user = user
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
481 Session.add(ugm)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
482 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
483 return ugm
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
484
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
485 class Repository(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
486 __tablename__ = 'repositories'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
487 __table_args__ = (UniqueConstraint('repo_name'), {'extend_existing':True},)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
488
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
489 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
490 repo_name = Column("repo_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
491 clone_uri = Column("clone_uri", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=False, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
492 repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
493 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
494 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
495 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
496 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
497 description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
498 created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
499
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
500 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
501 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
502
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
503
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
504 user = relationship('User')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
505 fork = relationship('Repository', remote_side=repo_id)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
506 group = relationship('RepoGroup')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
507 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
508 users_group_to_perm = relationship('UserGroupRepoToPerm', cascade='all')
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
509 stats = relationship('Statistics', cascade='all', uselist=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
510
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
511 followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
512
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
513 logs = relationship('UserLog', cascade='all')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
514
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
515 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
516 return "<%s('%s:%s')>" % (self.__class__.__name__,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
517 self.repo_id, self.repo_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
518
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
519 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
520 def url_sep(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
521 return '/'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
522
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
523 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
524 def get_by_repo_name(cls, repo_name):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
525 q = Session.query(cls).filter(cls.repo_name == repo_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
526 q = q.options(joinedload(Repository.fork))\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
527 .options(joinedload(Repository.user))\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
528 .options(joinedload(Repository.group))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
529 return q.one()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
530
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
531 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
532 def get_repo_forks(cls, repo_id):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
533 return cls.query().filter(Repository.fork_id == repo_id)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
534
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
535 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
536 def base_path(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
537 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
538 Returns base path when all repos are stored
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
539
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
540 :param cls:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
541 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
542 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
543 cls.url_sep())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
544 q.options(FromCache("sql_cache_short", "repository_repo_path"))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
545 return q.one().ui_value
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
546
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
547 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
548 def just_name(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
549 return self.repo_name.split(Repository.url_sep())[-1]
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
550
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
551 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
552 def groups_with_parents(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
553 groups = []
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
554 if self.group is None:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
555 return groups
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
556
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
557 cur_gr = self.group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
558 groups.insert(0, cur_gr)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
559 while 1:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
560 gr = getattr(cur_gr, 'parent_group', None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
561 cur_gr = cur_gr.parent_group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
562 if gr is None:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
563 break
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
564 groups.insert(0, gr)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
565
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
566 return groups
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
567
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
568 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
569 def groups_and_repo(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
570 return self.groups_with_parents, self.just_name
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
571
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
572 @LazyProperty
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
573 def repo_path(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
574 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
575 Returns base full path for that repository means where it actually
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
576 exists on a filesystem
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
577 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
578 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
579 Repository.url_sep())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
580 q.options(FromCache("sql_cache_short", "repository_repo_path"))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
581 return q.one().ui_value
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
582
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
583 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
584 def repo_full_path(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
585 p = [self.repo_path]
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
586 # we need to split the name by / since this is how we store the
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
587 # names in the database, but that eventually needs to be converted
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
588 # into a valid system path
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
589 p += self.repo_name.split(Repository.url_sep())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
590 return os.path.join(*p)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
591
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
592 def get_new_name(self, repo_name):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
593 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
594 returns new full repository name based on assigned group and new new
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
595
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
596 :param group_name:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
597 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
598 path_prefix = self.group.full_path_splitted if self.group else []
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
599 return Repository.url_sep().join(path_prefix + [repo_name])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
600
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
601 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
602 def _ui(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
603 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
604 Creates an db based ui object for this repository
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
605 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
606 from mercurial import ui
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
607 from mercurial import config
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
608 baseui = ui.ui()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
609
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
610 #clean the baseui object
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
611 baseui._ocfg = config.config()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
612 baseui._ucfg = config.config()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
613 baseui._tcfg = config.config()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
614
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
615
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
616 ret = RhodeCodeUi.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
617 .options(FromCache("sql_cache_short", "repository_repo_ui")).all()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
618
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
619 hg_ui = ret
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
620 for ui_ in hg_ui:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
621 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: 2214
diff changeset
622 log.debug('settings ui from db: [%s] %s=%s', ui_.ui_section,
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
623 ui_.ui_key, ui_.ui_value)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
624 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
625
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
626 return baseui
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
627
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
628 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
629 def is_valid(cls, repo_name):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
630 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
631 returns True if given repo name is a valid filesystem repository
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
632
1819
9451a569aee5 sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
633 :param cls:
9451a569aee5 sphinx doc cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
634 :param repo_name:
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
635 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
636 from rhodecode.lib.utils import is_valid_repo
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
637
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
638 return is_valid_repo(repo_name, cls.base_path())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
639
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
640
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
641 #==========================================================================
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
642 # SCM PROPERTIES
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
643 #==========================================================================
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
644
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
645 def get_changeset(self, rev):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
646 return get_changeset_safe(self.scm_instance, rev)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
647
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
648 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
649 def tip(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
650 return self.get_changeset('tip')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
651
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
652 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
653 def author(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
654 return self.tip.author
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
655
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
656 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
657 def last_change(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
658 return self.scm_instance.last_change
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
659
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
660 #==========================================================================
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
661 # SCM CACHE INSTANCE
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
662 #==========================================================================
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
663
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
664 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
665 def invalidate(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
666 return CacheInvalidation.invalidate(self.repo_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
667
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
668 def set_invalidate(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
669 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
670 set a cache for invalidation for this instance
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
671 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
672 CacheInvalidation.set_invalidate(self.repo_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
673
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
674 @LazyProperty
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
675 def scm_instance(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
676 return self.__get_instance()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
677
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
678 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
679 def scm_instance_cached(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
680 @cache_region('long_term')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
681 def _c(repo_name):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
682 return self.__get_instance()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
683 rn = self.repo_name
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
684
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
685 inv = self.invalidate
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
686 if inv is not None:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
687 region_invalidate(_c, None, rn)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
688 # update our cache
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
689 CacheInvalidation.set_valid(inv.cache_key)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
690 return _c(rn)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
691
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
692 def __get_instance(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
693
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
694 repo_full_path = self.repo_full_path
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
695
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
696 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
697 alias = get_scm(repo_full_path)[0]
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
698 log.debug('Creating instance of %s repository' % alias)
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
699 backend = get_backend(alias)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
700 except VCSError:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
701 log.error(traceback.format_exc())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
702 log.error('Perhaps this repository is in db and not in '
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
703 'filesystem run rescan repositories with '
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
704 '"destroy old data " option from admin panel')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
705 return
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
706
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
707 if alias == 'hg':
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
708
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
709 repo = backend(safe_str(repo_full_path), create=False,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
710 baseui=self._ui)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
711 # skip hidden web repository
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
712 if repo._get_hidden():
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
713 return
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
714 else:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
715 repo = backend(repo_full_path, create=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
716
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
717 return repo
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
718
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
719
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
720 class Group(Base, BaseModel):
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
721 __tablename__ = 'groups'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
722 __table_args__ = (UniqueConstraint('group_name', 'group_parent_id'),
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
723 CheckConstraint('group_id != group_parent_id'), {'extend_existing':True},)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
724 __mapper_args__ = {'order_by':'group_name'}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
725
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
726 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
727 group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
728 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
729 group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
730
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
731 parent_group = relationship('Group', remote_side=group_id)
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
732
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
733 def __init__(self, group_name='', parent_group=None):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
734 self.group_name = group_name
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
735 self.parent_group = parent_group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
736
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
737 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
738 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
739 self.group_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
740
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
741 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
742 def groups_choices(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
743 from webhelpers.html import literal as _literal
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
744 repo_groups = [('', '')]
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
745 sep = ' &raquo; '
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
746 _name = lambda k: _literal(sep.join(k))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
747
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
748 repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
749 for x in cls.query().all()])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
750
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
751 repo_groups = sorted(repo_groups, key=lambda t: t[1].split(sep)[0])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
752 return repo_groups
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
753
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
754 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
755 def url_sep(cls):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
756 return '/'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
757
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
758 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
759 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
760 if case_insensitive:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
761 gr = cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
762 .filter(cls.group_name.ilike(group_name))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
763 else:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
764 gr = cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
765 .filter(cls.group_name == group_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
766 if cache:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
767 gr = gr.options(FromCache("sql_cache_short",
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
768 "get_group_%s" % group_name))
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
769 return gr.scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
770
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
771 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
772 def parents(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
773 parents_recursion_limit = 5
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
774 groups = []
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
775 if self.parent_group is None:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
776 return groups
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
777 cur_gr = self.parent_group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
778 groups.insert(0, cur_gr)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
779 cnt = 0
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
780 while 1:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
781 cnt += 1
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
782 gr = getattr(cur_gr, 'parent_group', None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
783 cur_gr = cur_gr.parent_group
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
784 if gr is None:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
785 break
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
786 if cnt == parents_recursion_limit:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
787 # this will prevent accidental infinit loops
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
788 log.error('group nested more than %s' %
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
789 parents_recursion_limit)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
790 break
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
791
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
792 groups.insert(0, gr)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
793 return groups
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
794
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
795 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
796 def children(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
797 return Group.query().filter(Group.parent_group == self)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
798
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
799 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
800 def name(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
801 return self.group_name.split(Group.url_sep())[-1]
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
802
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
803 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
804 def full_path(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
805 return self.group_name
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
806
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
807 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
808 def full_path_splitted(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
809 return self.group_name.split(Group.url_sep())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
810
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
811 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
812 def repositories(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
813 return Repository.query().filter(Repository.group == self)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
814
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
815 @property
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
816 def repositories_recursive_count(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
817 cnt = self.repositories.count()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
818
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
819 def children_count(group):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
820 cnt = 0
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
821 for child in group.children:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
822 cnt += child.repositories.count()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
823 cnt += children_count(child)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
824 return cnt
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
825
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
826 return cnt + children_count(self)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
827
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
828
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
829 def get_new_name(self, group_name):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
830 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
831 returns new full group name based on parent and new name
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
832
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
833 :param group_name:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
834 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
835 path_prefix = (self.parent_group.full_path_splitted if
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
836 self.parent_group else [])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
837 return Group.url_sep().join(path_prefix + [group_name])
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
838
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
839
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
840 class Permission(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
841 __tablename__ = 'permissions'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
842 __table_args__ = {'extend_existing':True}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
843 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
844 permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
845 permission_longname = Column("permission_longname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
846
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
847 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
848 return "<%s('%s:%s')>" % (self.__class__.__name__,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
849 self.permission_id, self.permission_name)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
850
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
851 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
852 def get_by_key(cls, key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
853 return cls.query().filter(cls.permission_name == key).scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
854
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
855 class UserRepoToPerm(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
856 __tablename__ = 'repo_to_perm'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
857 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
858 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
859 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
860 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
861 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
862
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
863 user = relationship('User')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
864 permission = relationship('Permission')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
865 repository = relationship('Repository')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
866
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
867 class UserToPerm(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
868 __tablename__ = 'user_to_perm'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
869 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
870 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
871 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
872 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
873
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
874 user = relationship('User')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
875 permission = relationship('Permission')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
876
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
877 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
878 def has_perm(cls, user_id, perm):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
879 if not isinstance(perm, Permission):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
880 raise Exception('perm needs to be an instance of Permission class')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
881
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
882 return cls.query().filter(cls.user_id == user_id)\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
883 .filter(cls.permission == perm).scalar() is not None
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
884
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
885 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
886 def grant_perm(cls, user_id, perm):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
887 if not isinstance(perm, Permission):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
888 raise Exception('perm needs to be an instance of Permission class')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
889
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
890 new = cls()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
891 new.user_id = user_id
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
892 new.permission = perm
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
893 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
894 Session.add(new)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
895 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
896 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
897 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
898
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
899
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
900 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
901 def revoke_perm(cls, user_id, perm):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
902 if not isinstance(perm, Permission):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
903 raise Exception('perm needs to be an instance of Permission class')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
904
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
905 try:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
906 cls.query().filter(cls.user_id == user_id) \
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
907 .filter(cls.permission == perm).delete()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
908 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
909 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
910 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
911
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
912 class UserGroupRepoToPerm(Base, BaseModel):
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
913 __tablename__ = 'users_group_repo_to_perm'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
914 __table_args__ = (UniqueConstraint('repository_id', 'users_group_id', 'permission_id'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
915 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
916 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
917 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
918 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
919
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
920 users_group = relationship('UserGroup')
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
921 permission = relationship('Permission')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
922 repository = relationship('Repository')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
923
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
924 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
925 return '<userGroup:%s => %s >' % (self.users_group, self.repository)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
926
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
927 class UserGroupToPerm(Base, BaseModel):
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
928 __tablename__ = 'users_group_to_perm'
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
929 __table_args__ = {'extend_existing':True}
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
930 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
931 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
932 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
933
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3133
diff changeset
934 users_group = relationship('UserGroup')
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
935 permission = relationship('Permission')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
936
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
937
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
938 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
939 def has_perm(cls, users_group_id, perm):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
940 if not isinstance(perm, Permission):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
941 raise Exception('perm needs to be an instance of Permission class')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
942
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
943 return cls.query().filter(cls.users_group_id ==
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
944 users_group_id)\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
945 .filter(cls.permission == perm)\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
946 .scalar() is not None
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
947
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
948 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
949 def grant_perm(cls, users_group_id, perm):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
950 if not isinstance(perm, Permission):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
951 raise Exception('perm needs to be an instance of Permission class')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
952
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
953 new = cls()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
954 new.users_group_id = users_group_id
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
955 new.permission = perm
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
956 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
957 Session.add(new)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
958 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
959 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
960 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
961
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
962
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
963 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
964 def revoke_perm(cls, users_group_id, perm):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
965 if not isinstance(perm, Permission):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
966 raise Exception('perm needs to be an instance of Permission class')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
967
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
968 try:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3417
diff changeset
969 cls.query().filter(cls.users_group_id == users_group_id) \
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
970 .filter(cls.permission == perm).delete()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
971 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
972 except:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
973 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
974
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
975
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
976 class UserRepoGroupToPerm(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
977 __tablename__ = 'group_to_perm'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
978 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
979
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
980 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
981 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
982 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
983 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
984
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
985 user = relationship('User')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
986 permission = relationship('Permission')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
987 group = relationship('RepoGroup')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
988
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
989 class Statistics(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
990 __tablename__ = 'statistics'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
991 __table_args__ = (UniqueConstraint('repository_id'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
992 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
993 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
994 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
995 commit_activity = Column("commit_activity", LargeBinary(1000000), nullable=False)#JSON data
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
996 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
997 languages = Column("languages", LargeBinary(1000000), nullable=False)#JSON data
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
998
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
999 repository = relationship('Repository', single_parent=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1000
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1001 class UserFollowing(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1002 __tablename__ = 'user_followings'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1003 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1004 UniqueConstraint('user_id', 'follows_user_id')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1005 , {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1006
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1007 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1008 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1009 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1010 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1011 follows_from = Column('follows_from', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1012
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1013 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1014
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1015 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1016 follows_repository = relationship('Repository', order_by='Repository.repo_name')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1017
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1018
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1019 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1020 def get_repo_followers(cls, repo_id):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1021 return cls.query().filter(cls.follows_repo_id == repo_id)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1022
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1023 class CacheInvalidation(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1024 __tablename__ = 'cache_invalidation'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1025 __table_args__ = (UniqueConstraint('cache_key'), {'extend_existing':True})
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1026 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1027 cache_key = Column("cache_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1028 cache_args = Column("cache_args", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1029 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1030
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1031
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1032 def __init__(self, cache_key, cache_args=''):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1033 self.cache_key = cache_key
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1034 self.cache_args = cache_args
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1035 self.cache_active = False
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1036
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1037 def __repr__(self):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1038 return "<%s('%s:%s')>" % (self.__class__.__name__,
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1039 self.cache_id, self.cache_key)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1040
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1041 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1042 def invalidate(cls, key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1043 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1044 Returns Invalidation object if this given key should be invalidated
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1045 None otherwise. `cache_active = False` means that this cache
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1046 state is not valid and needs to be invalidated
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
1047
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1048 :param key:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1049 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1050 return cls.query()\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1051 .filter(CacheInvalidation.cache_key == key)\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1052 .filter(CacheInvalidation.cache_active == False)\
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1053 .scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1054
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1055 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1056 def set_invalidate(cls, key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1057 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1058 Mark this Cache key for invalidation
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
1059
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1060 :param key:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1061 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1062
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1063 log.debug('marking %s for invalidation' % key)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1064 inv_obj = Session.query(cls)\
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1065 .filter(cls.cache_key == key).scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1066 if inv_obj:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1067 inv_obj.cache_active = False
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1068 else:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1069 log.debug('cache key not found in invalidation db -> creating one')
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1070 inv_obj = CacheInvalidation(key)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1071
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1072 try:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1073 Session.add(inv_obj)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1074 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1075 except Exception:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1076 log.error(traceback.format_exc())
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1077 Session.rollback()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1078
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1079 @classmethod
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1080 def set_valid(cls, key):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1081 """
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1082 Mark this cache key as active and currently cached
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
1083
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1084 :param key:
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1085 """
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
1086 inv_obj = Session.query(CacheInvalidation)\
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1087 .filter(CacheInvalidation.cache_key == key).scalar()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1088 inv_obj.cache_active = True
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1089 Session.add(inv_obj)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1090 Session.commit()
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1091
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1092 class DbMigrateVersion(Base, BaseModel):
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1093 __tablename__ = 'db_migrate_version'
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1094 __table_args__ = {'extend_existing':True}
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1095 repository_id = Column('repository_id', String(250), primary_key=True)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1096 repository_path = Column('repository_path', Text)
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1097 version = Column('version', Integer)