Show More
@@ -42,7 +42,6 b'' | |||
|
42 | 42 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
43 | 43 | |
|
44 | 44 | import logging |
|
45 | from rhodecode.model.db import User, Repository, Permission | |
|
46 | 45 | from rhodecode.model import meta |
|
47 | 46 | |
|
48 | 47 | log = logging.getLogger(__name__) |
@@ -68,11 +67,13 b' class BaseModel(object):' | |||
|
68 | 67 | :param sa: If passed it reuses this session instead of creating a new one |
|
69 | 68 | """ |
|
70 | 69 | |
|
70 | cls = None # override in child class | |
|
71 | ||
|
71 | 72 | def __init__(self, sa=None): |
|
72 | 73 | if sa is not None: |
|
73 | 74 | self.sa = sa |
|
74 | 75 | else: |
|
75 | self.sa = meta.Session | |
|
76 | self.sa = meta.Session() | |
|
76 | 77 | |
|
77 | 78 | def _get_instance(self, cls, instance, callback=None): |
|
78 | 79 | """ |
@@ -104,6 +105,7 b' class BaseModel(object):' | |||
|
104 | 105 | :param user: |
|
105 | 106 | :type user: UserID, username, or User instance |
|
106 | 107 | """ |
|
108 | from rhodecode.model.db import User | |
|
107 | 109 | return self._get_instance(User, user, |
|
108 | 110 | callback=User.get_by_username) |
|
109 | 111 | |
@@ -114,6 +116,7 b' class BaseModel(object):' | |||
|
114 | 116 | :param repository: |
|
115 | 117 | :type repository: RepoID, repository name or Repository Instance |
|
116 | 118 | """ |
|
119 | from rhodecode.model.db import Repository | |
|
117 | 120 | return self._get_instance(Repository, repository, |
|
118 | 121 | callback=Repository.get_by_repo_name) |
|
119 | 122 | |
@@ -124,5 +127,12 b' class BaseModel(object):' | |||
|
124 | 127 | :param permission: |
|
125 | 128 | :type permission: PermissionID, permission_name or Permission instance |
|
126 | 129 | """ |
|
130 | from rhodecode.model.db import Permission | |
|
127 | 131 | return self._get_instance(Permission, permission, |
|
128 | 132 | callback=Permission.get_by_key) |
|
133 | ||
|
134 | def get_all(self): | |
|
135 | """ | |
|
136 | Returns all instances of what is defined in `cls` class variable | |
|
137 | """ | |
|
138 | return self.cls.getAll() |
General Comments 0
You need to be logged in to leave comments.
Login now