# HG changeset patch # User Søren Løvborg # Date 1470235894 -7200 # Node ID 974d6470cbec64bf6fc9840047a21f3f0a0a4cac # Parent 1e52ed5c37aa31aadf024b0b8409c553af25071c model: inline BaseModel.get_all This is just needless indirection (and doesn't actually add any abstraction on top of the database object), so inline all calls to it. Don't touch PullRequestModel.get_all, though, since it is an entirely unrelated method that just shadows the inherited get_all. diff -r 1e52ed5c37aa -r 974d6470cbec kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py Wed Aug 03 15:31:23 2016 +0200 +++ b/kallithea/controllers/api/api.py Wed Aug 03 16:51:34 2016 +0200 @@ -48,7 +48,7 @@ from kallithea.model.gist import GistModel from kallithea.model.db import ( Repository, Setting, UserIpMap, Permission, User, Gist, - RepoGroup) + RepoGroup, UserGroup) from kallithea.lib.compat import json from kallithea.lib.exceptions import ( DefaultUserException, UserGroupsAssignedException) @@ -885,7 +885,7 @@ result = [] _perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin',) extras = {'user': apiuser} - for user_group in UserGroupList(UserGroupModel().get_all(), + for user_group in UserGroupList(UserGroup.get_all(), perm_set=_perms, extra_kwargs=extras): result.append(user_group.get_api_data()) return result @@ -1323,7 +1323,7 @@ if not HasPermissionAnyApi('hg.admin')(user=apiuser): repos = RepoModel().get_all_user_repos(user=apiuser) else: - repos = RepoModel().get_all() + repos = Repository.get_all() for repo in repos: result.append(repo.get_api_data()) diff -r 1e52ed5c37aa -r 974d6470cbec kallithea/model/__init__.py --- a/kallithea/model/__init__.py Wed Aug 03 15:31:23 2016 +0200 +++ b/kallithea/model/__init__.py Wed Aug 03 16:51:34 2016 +0200 @@ -132,10 +132,3 @@ from kallithea.model.db import Permission return self._get_instance(Permission, permission, callback=Permission.get_by_key) - - @classmethod - def get_all(cls): - """ - Returns all instances of what is defined in `cls` class variable - """ - return cls.cls.get_all() diff -r 1e52ed5c37aa -r 974d6470cbec kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py Wed Aug 03 15:31:23 2016 +0200 +++ b/kallithea/tests/api/api_base.py Wed Aug 03 16:51:34 2016 +0200 @@ -880,7 +880,7 @@ response = api_call(self, params) result = [] - for repo in RepoModel().get_all(): + for repo in Repository.get_all(): result.append(repo.get_api_data()) ret = jsonify(result) diff -r 1e52ed5c37aa -r 974d6470cbec kallithea/tests/fixture.py --- a/kallithea/tests/fixture.py Wed Aug 03 15:31:23 2016 +0200 +++ b/kallithea/tests/fixture.py Wed Aug 03 16:51:34 2016 +0200 @@ -18,7 +18,7 @@ import os import time from kallithea.tests import * -from kallithea.model.db import Repository, User, RepoGroup, UserGroup +from kallithea.model.db import Repository, User, RepoGroup, UserGroup, Gist from kallithea.model.meta import Session from kallithea.model.repo import RepoModel from kallithea.model.user import UserModel @@ -252,7 +252,7 @@ return gist def destroy_gists(self, gistid=None): - for g in GistModel.cls.get_all(): + for g in Gist.get_all(): if gistid: if gistid == g.gist_access_id: GistModel().delete(g) diff -r 1e52ed5c37aa -r 974d6470cbec kallithea/tests/models/test_user_groups.py --- a/kallithea/tests/models/test_user_groups.py Wed Aug 03 15:31:23 2016 +0200 +++ b/kallithea/tests/models/test_user_groups.py Wed Aug 03 16:51:34 2016 +0200 @@ -1,4 +1,4 @@ -from kallithea.model.db import User +from kallithea.model.db import User, UserGroup from kallithea.tests import * from kallithea.tests.fixture import Fixture @@ -14,7 +14,7 @@ def teardown_method(self, method): # delete all groups - for gr in UserGroupModel.get_all(): + for gr in UserGroup.get_all(): fixture.destroy_user_group(gr) Session().commit() @@ -30,7 +30,7 @@ def test_enforce_groups(self, pre_existing, regular_should_be, external_should_be, groups, expected): # delete all groups - for gr in UserGroupModel.get_all(): + for gr in UserGroup.get_all(): fixture.destroy_user_group(gr) Session().commit()