annotate kallithea/model/__init__.py @ 5375:0210d0b769d4

cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
author Mads Kiilerich <madski@unity3d.com>
date Sun, 09 Aug 2015 02:29:46 +0200
parents 63bed817308c
children 0ad053c172fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
1 # -*- coding: utf-8 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
3 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
5 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
6 #
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
7 # This program is distributed in the hope that it will be useful,
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
10 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
11 #
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
12 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
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: 4089
diff changeset
14 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
15 kallithea.model.__init__
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
18 The application's model objects
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
19
4211
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
20 This file was forked by the Kallithea project in July 2014.
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
21 Original author and date, and relevant copyright and licensing information is below:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
22 :created_on: Nov 25, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
23 :author: marcink
4211
1948ede028ef RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4208
diff changeset
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
4208
ad38f9f93b3b Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
25 :license: GPLv3, see LICENSE.md for more details.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
26
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
27
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
28 :example:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
29
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
30 .. code-block:: python
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
31
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
32 from paste.deploy import appconfig
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
33 from pylons import config
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
34 from sqlalchemy import engine_from_config
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
35 from kallithea.config.environment import load_environment
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
36
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
37 conf = appconfig('config:development.ini', relative_to = './../../')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
38 load_environment(conf.global_conf, conf.local_conf)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
39
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
40 engine = engine_from_config(config, 'sqlalchemy.')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
41 init_model(engine)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
42 # RUN YOUR CODE HERE
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
43
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
44 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
45
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
46
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
47 import logging
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
48 from kallithea.model import meta
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
49 from kallithea.lib.utils2 import safe_str, obfuscate_url_pw
1155
37a9421f32a0 Added handy methods to Repository model for fetching groups with parents
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
50
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
51 log = logging.getLogger(__name__)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
52
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
53
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
54 def init_model(engine):
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
55 """
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
56 Initializes db session, bind the engine with the metadata,
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
57 Call this before using any of the tables or classes in the model,
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
58 preferably once in application start
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
59
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
60 :param engine: engine to bind to
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
61 """
2882
12fce5e499d5 obfuscate password in logs for engine connection string
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
62 engine_str = obfuscate_url_pw(str(engine.url))
5375
0210d0b769d4 cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents: 5306
diff changeset
63 log.info("initializing db for %s", engine_str)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
64 meta.Base.metadata.bind = engine
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
65
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
66
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
67 class BaseModel(object):
1751
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
68 """
4212
24c0d584ba86 General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4211
diff changeset
69 Base Model for all Kallithea models, it adds sql alchemy session
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
70 into instance of model
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1155
diff changeset
71
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
72 :param sa: If passed it reuses this session instead of creating a new one
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
73 """
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
74
2521
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
75 cls = None # override in child class
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
76
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
77 def __init__(self, sa=None):
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
78 if sa is not None:
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
79 self.sa = sa
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
80 else:
2521
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
81 self.sa = meta.Session()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
82
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
83 def _get_instance(self, cls, instance, callback=None):
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
84 """
4089
a5888ca796b5 Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
85 Gets instance of given cls using some simple lookup mechanism.
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
86
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
87 :param cls: class to fetch
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
88 :param instance: int or Instance
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
89 :param callback: callback to call if all lookups failed
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
90 """
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
91
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
92 if isinstance(instance, cls):
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
93 return instance
2672
169807710db2 fixed possible unicode errors on repo get function
Marcin Kuzminski <marcin@python-works.com>
parents: 2521
diff changeset
94 elif isinstance(instance, (int, long)) or safe_str(instance).isdigit():
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
95 return cls.get(instance)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
96 else:
5306
63bed817308c cleanup: check for None object identity in cases where that is what the 'contract' says
Mads Kiilerich <madski@unity3d.com>
parents: 4212
diff changeset
97 if instance is not None:
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
98 if callback is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
99 raise Exception(
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
100 'given object must be int, long or Instance of %s '
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
101 'got %s, no callback provided' % (cls, type(instance))
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
102 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
103 else:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
104 return callback(instance)
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
105
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
106 def _get_user(self, user):
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
107 """
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
108 Helper method to get user by ID, or username fallback
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
109
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 2882
diff changeset
110 :param user: UserID, username, or User instance
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
111 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
112 from kallithea.model.db import User
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
113 return self._get_instance(User, user,
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
114 callback=User.get_by_username)
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
115
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
116 def _get_repo(self, repository):
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
117 """
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
118 Helper method to get repository by ID, or repository name
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
119
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 2882
diff changeset
120 :param repository: RepoID, repository name or Repository Instance
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
121 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
122 from kallithea.model.db import Repository
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
123 return self._get_instance(Repository, repository,
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
124 callback=Repository.get_by_repo_name)
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
125
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
126 def _get_perm(self, permission):
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
127 """
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
128 Helper method to get permission by ID, or permission name
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
129
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 2882
diff changeset
130 :param permission: PermissionID, permission_name or Permission instance
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
131 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
132 from kallithea.model.db import Permission
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
133 return self._get_instance(Permission, permission,
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
134 callback=Permission.get_by_key)
2521
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
135
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
136 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
137 def get_all(cls):
2521
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
138 """
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
139 Returns all instances of what is defined in `cls` class variable
e4d2271e1193 Added get_all method to BaseModel, requires to define cls variable in child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
140 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
141 return cls.cls.getAll()