annotate rhodecode/model/__init__.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 a5888ca796b5
children 7e5f8c12a3fc
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 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
15 rhodecode.model.__init__
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
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
20 :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
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
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: 4089
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: 4089
diff changeset
24
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
25
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
26 :example:
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 .. 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
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 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
31 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
32 from sqlalchemy import engine_from_config
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 rhodecode.config.environment import load_environment
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
34
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
35 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
36 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
37
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
38 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
39 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
40 # 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
41
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
42 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
43
759
a7f50911a945 Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
44
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
45 import logging
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 473
diff changeset
46 from rhodecode.model import meta
2882
12fce5e499d5 obfuscate password in logs for engine connection string
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
47 from rhodecode.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
48
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49 log = logging.getLogger(__name__)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
50
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
51
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
52 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
53 """
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
54 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
55 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
56 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
57
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
58 :param engine: engine to bind to
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
59 """
2882
12fce5e499d5 obfuscate password in logs for engine connection string
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
60 engine_str = obfuscate_url_pw(str(engine.url))
12fce5e499d5 obfuscate password in logs for engine connection string
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
61 log.info("initializing db for %s" % engine_str)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
62 meta.Base.metadata.bind = engine
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
63
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
64
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
65 class BaseModel(object):
1751
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
66 """
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
67 Base Model for all RhodeCode models, it adds sql alchemy session
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
68 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
69
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 759
diff changeset
70 :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
71 """
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
72
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
73 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
74
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
75 def __init__(self, sa=None):
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
76 if sa is not None:
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
77 self.sa = sa
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
78 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
79 self.sa = meta.Session()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
80
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
81 def _get_instance(self, cls, instance, callback=None):
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
82 """
4089
a5888ca796b5 Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
83 Gets instance of given cls using some simple lookup mechanism.
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
84
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
85 :param cls: class to fetch
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
86 :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
87 :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
88 """
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
89
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
90 if isinstance(instance, cls):
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
91 return instance
2672
169807710db2 fixed possible unicode errors on repo get function
Marcin Kuzminski <marcin@python-works.com>
parents: 2521
diff changeset
92 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
93 return cls.get(instance)
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
94 else:
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
95 if instance:
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
96 if callback is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
97 raise Exception(
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
98 'given object must be int, long or Instance of %s '
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
99 '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
100 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
101 else:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
102 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
103
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
104 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
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 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
107
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 2882
diff changeset
108 :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
109 """
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
110 from rhodecode.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
111 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
112 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
113
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 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
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 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
117
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 2882
diff changeset
118 :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
119 """
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
120 from rhodecode.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
121 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
122 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
123
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 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
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 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
127
3840
dc4644865e8b Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents: 2882
diff changeset
128 :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
129 """
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
130 from rhodecode.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
131 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
132 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
133
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
134 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
135 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
136 """
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
137 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
138 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
139 return cls.cls.getAll()