Changeset - 974d6470cbec
[Not reviewed]
default
0 5 0
Søren Løvborg - 9 years ago 2016-08-03 16:51:34
sorenl@unity3d.com
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.
5 files changed with 9 insertions and 16 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/api/api.py
Show inline comments
 
@@ -48,7 +48,7 @@ from kallithea.model.user_group import U
 
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 @@ class ApiController(JSONRPCController):
 
        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 @@ class ApiController(JSONRPCController):
 
        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())
kallithea/model/__init__.py
Show inline comments
 
@@ -132,10 +132,3 @@ class BaseModel(object):
 
        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()
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -880,7 +880,7 @@ class _BaseTestApi(object):
 
        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)
 

	
kallithea/tests/fixture.py
Show inline comments
 
@@ -18,7 +18,7 @@ Helpers for fixture generation
 
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 @@ class Fixture(object):
 
        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)
kallithea/tests/models/test_user_groups.py
Show inline comments
 
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 @@ class TestUserGroups(TestController):
 

	
 
    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 @@ class TestUserGroups(TestController):
 
    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()
 

	
0 comments (0 inline, 0 general)