Changeset - fddd8e3fc157
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2012-06-20 21:42:05
marcin@python-works.com
use get_or_404 where possible
4 files changed with 16 insertions and 13 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/repos_groups.py
Show inline comments
 
@@ -75,7 +75,7 @@ class ReposGroupsController(BaseControll
 
        """
 
        self.__load_defaults()
 

	
 
        repo_group = RepoGroup.get(group_id)
 
        repo_group = RepoGroup.get_or_404(group_id)
 

	
 
        data = repo_group.get_dict()
 

	
 
@@ -277,12 +277,9 @@ class ReposGroupsController(BaseControll
 
        """GET /repos_groups/id: Show a specific item"""
 
        # url('repos_group', id=ID)
 

	
 
        c.group = RepoGroup.get(id)
 
        c.group = RepoGroup.get_or_404(id)
 

	
 
        if c.group:
 
            c.group_repos = c.group.repositories.all()
 
        else:
 
            return redirect(url('home'))
 
        c.group_repos = c.group.repositories.all()
 

	
 
        #overwrite our cached list with current filter
 
        gr_filter = c.group_repos
rhodecode/controllers/admin/users.py
Show inline comments
 
@@ -172,9 +172,8 @@ class UsersController(BaseController):
 
    def edit(self, id, format='html'):
 
        """GET /users/id/edit: Form to edit an existing item"""
 
        # url('edit_user', id=ID)
 
        c.user = User.get(id)
 
        if not c.user:
 
            return redirect(url('users'))
 
        c.user = User.get_or_404(id)
 

	
 
        if c.user.username == 'default':
 
            h.flash(_("You can't edit this user"), category='warning')
 
            return redirect(url('users'))
rhodecode/controllers/pullrequests.py
Show inline comments
 
@@ -198,11 +198,8 @@ class PullrequestsController(BaseRepoCon
 
        repo_model = RepoModel()
 
        c.users_array = repo_model.get_users_js()
 
        c.users_groups_array = repo_model.get_users_groups_js()
 
        c.pull_request = PullRequest.get(pull_request_id)
 
        c.pull_request = PullRequest.get_or_404(pull_request_id)
 

	
 
        # valid ID
 
        if not c.pull_request:
 
            raise HTTPNotFound
 
        cc_model = ChangesetCommentsModel()
 
        cs_model = ChangesetStatusModel()
 
        _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
rhodecode/model/db.py
Show inline comments
 
@@ -35,6 +35,7 @@ from sqlalchemy.ext.hybrid import hybrid
 
from sqlalchemy.orm import relationship, joinedload, class_mapper, validates
 
from sqlalchemy.exc import DatabaseError
 
from beaker.cache import cache_region, region_invalidate
 
from webob.exc import HTTPNotFound
 

	
 
from pylons.i18n.translation import lazy_ugettext as _
 

	
 
@@ -51,6 +52,7 @@ from rhodecode.lib.caching_query import 
 
from rhodecode.model.meta import Base, Session
 

	
 

	
 

	
 
URL_SEP = '/'
 
log = logging.getLogger(__name__)
 

	
 
@@ -142,6 +144,14 @@ class BaseModel(object):
 
            return cls.query().get(id_)
 

	
 
    @classmethod
 
    def get_or_404(cls, id_):
 
        if id_:
 
            res = cls.query().get(id_)
 
            if not res:
 
                raise HTTPNotFound
 
            return res
 

	
 
    @classmethod
 
    def getAll(cls):
 
        return cls.query().all()
 

	
0 comments (0 inline, 0 general)