##// END OF EJS Templates
home: don't crash in branch_tag_switcher when an invalid repo name is given
Mads Kiilerich -
r3437:deb51ab0 beta
parent child Browse files
Show More
@@ -1,87 +1,87 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.home
3 rhodecode.controllers.home
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Home controller for Rhodecode
6 Home controller for Rhodecode
7
7
8 :created_on: Feb 18, 2010
8 :created_on: Feb 18, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software: you can redistribute it and/or modify
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
16 # (at your option) any later version.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
25
26 import logging
26 import logging
27
27
28 from pylons import tmpl_context as c, request
28 from pylons import tmpl_context as c, request
29 from pylons.i18n.translation import _
29 from pylons.i18n.translation import _
30 from webob.exc import HTTPBadRequest
30 from webob.exc import HTTPBadRequest
31 from sqlalchemy.sql.expression import func
31 from sqlalchemy.sql.expression import func
32
32
33 import rhodecode
33 import rhodecode
34 from rhodecode.lib import helpers as h
34 from rhodecode.lib import helpers as h
35 from rhodecode.lib.ext_json import json
35 from rhodecode.lib.ext_json import json
36 from rhodecode.lib.auth import LoginRequired
36 from rhodecode.lib.auth import LoginRequired
37 from rhodecode.lib.base import BaseController, render
37 from rhodecode.lib.base import BaseController, render
38 from rhodecode.model.db import Repository
38 from rhodecode.model.db import Repository
39 from rhodecode.model.repo import RepoModel
39 from rhodecode.model.repo import RepoModel
40
40
41
41
42 log = logging.getLogger(__name__)
42 log = logging.getLogger(__name__)
43
43
44
44
45 class HomeController(BaseController):
45 class HomeController(BaseController):
46
46
47 @LoginRequired()
47 @LoginRequired()
48 def __before__(self):
48 def __before__(self):
49 super(HomeController, self).__before__()
49 super(HomeController, self).__before__()
50
50
51 def index(self):
51 def index(self):
52 c.groups = self.scm_model.get_repos_groups()
52 c.groups = self.scm_model.get_repos_groups()
53 c.group = None
53 c.group = None
54
54
55 if c.visual.lightweight_dashboard is False:
55 if c.visual.lightweight_dashboard is False:
56 c.repos_list = self.scm_model.get_repos()
56 c.repos_list = self.scm_model.get_repos()
57 ## lightweight version of dashboard
57 ## lightweight version of dashboard
58 else:
58 else:
59 c.repos_list = Repository.query()\
59 c.repos_list = Repository.query()\
60 .filter(Repository.group_id == None)\
60 .filter(Repository.group_id == None)\
61 .order_by(func.lower(Repository.repo_name))\
61 .order_by(func.lower(Repository.repo_name))\
62 .all()
62 .all()
63
63
64 repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list,
64 repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list,
65 admin=False)
65 admin=False)
66 #json used to render the grid
66 #json used to render the grid
67 c.data = json.dumps(repos_data)
67 c.data = json.dumps(repos_data)
68
68
69 return render('/index.html')
69 return render('/index.html')
70
70
71 def repo_switcher(self):
71 def repo_switcher(self):
72 if request.is_xhr:
72 if request.is_xhr:
73 all_repos = Repository.query().order_by(Repository.repo_name).all()
73 all_repos = Repository.query().order_by(Repository.repo_name).all()
74 c.repos_list = self.scm_model.get_repos(all_repos,
74 c.repos_list = self.scm_model.get_repos(all_repos,
75 sort_key='name_sort',
75 sort_key='name_sort',
76 simple=True)
76 simple=True)
77 return render('/repo_switcher_list.html')
77 return render('/repo_switcher_list.html')
78 else:
78 else:
79 raise HTTPBadRequest()
79 raise HTTPBadRequest()
80
80
81 def branch_tag_switcher(self, repo_name):
81 def branch_tag_switcher(self, repo_name):
82 if request.is_xhr:
82 if request.is_xhr:
83 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
83 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
84 if c.rhodecode_db_repo:
84 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
85 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
85 return render('/switch_to_list.html')
86 return render('/switch_to_list.html')
86 else:
87 raise HTTPBadRequest()
87 raise HTTPBadRequest()
General Comments 0
You need to be logged in to leave comments. Login now