changeset 6117:974d6470cbec

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.
author Søren Løvborg <sorenl@unity3d.com>
date Wed, 03 Aug 2016 16:51:34 +0200
parents 1e52ed5c37aa
children 3d1fcf67f299
files kallithea/controllers/api/api.py kallithea/model/__init__.py kallithea/tests/api/api_base.py kallithea/tests/fixture.py kallithea/tests/models/test_user_groups.py
diffstat 5 files changed, 9 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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())
--- 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()
--- 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)
 
--- 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)
--- 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()