##// END OF EJS Templates
fixed badRequest on views decorated by @jsonify
marcink -
r2970:6248c6fb beta
parent child Browse files
Show More
@@ -1,119 +1,119 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.home
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 Home controller for Rhodecode
7 7
8 8 :created_on: Feb 18, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 27
28 28 from pylons import tmpl_context as c, request
29 29 from pylons.i18n.translation import _
30 30 from webob.exc import HTTPBadRequest
31 31
32 32 import rhodecode
33 33 from rhodecode.lib import helpers as h
34 34 from rhodecode.lib.ext_json import json
35 35 from rhodecode.lib.auth import LoginRequired
36 36 from rhodecode.lib.base import BaseController, render
37 37 from rhodecode.model.db import Repository
38 38 from sqlalchemy.sql.expression import func
39 39
40 40 log = logging.getLogger(__name__)
41 41
42 42
43 43 class HomeController(BaseController):
44 44
45 45 @LoginRequired()
46 46 def __before__(self):
47 47 super(HomeController, self).__before__()
48 48
49 49 def index(self):
50 50 c.groups = self.scm_model.get_repos_groups()
51 51 c.group = None
52 52
53 53 if c.visual.lightweight_dashboard is False:
54 54 c.repos_list = self.scm_model.get_repos()
55 55 ## lightweight version of dashboard
56 56 else:
57 57 c.repos_list = Repository.query()\
58 58 .filter(Repository.group_id == None)\
59 59 .order_by(func.lower(Repository.repo_name))\
60 60 .all()
61 61 repos_data = []
62 62 total_records = len(c.repos_list)
63 63
64 64 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
65 65 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
66 66
67 67 quick_menu = lambda repo_name: (template.get_def("quick_menu")
68 68 .render(repo_name, _=_, h=h, c=c))
69 69 repo_lnk = lambda name, rtype, private, fork_of: (
70 70 template.get_def("repo_name")
71 71 .render(name, rtype, private, fork_of, short_name=False,
72 72 admin=False, _=_, h=h, c=c))
73 73 last_change = lambda last_change: (template.get_def("last_change")
74 74 .render(last_change, _=_, h=h, c=c))
75 75 rss_lnk = lambda repo_name: (template.get_def("rss")
76 76 .render(repo_name, _=_, h=h, c=c))
77 77 atom_lnk = lambda repo_name: (template.get_def("atom")
78 78 .render(repo_name, _=_, h=h, c=c))
79 79
80 80 for repo in c.repos_list:
81 81 repos_data.append({
82 82 "menu": quick_menu(repo.repo_name),
83 83 "raw_name": repo.repo_name.lower(),
84 84 "name": repo_lnk(repo.repo_name, repo.repo_type,
85 85 repo.private, repo.fork),
86 86 "last_change": last_change(repo.last_db_change),
87 87 "desc": repo.description,
88 88 "owner": h.person(repo.user.username),
89 89 "rss": rss_lnk(repo.repo_name),
90 90 "atom": atom_lnk(repo.repo_name),
91 91 })
92 92
93 93 c.data = json.dumps({
94 94 "totalRecords": total_records,
95 95 "startIndex": 0,
96 96 "sort": "name",
97 97 "dir": "asc",
98 98 "records": repos_data
99 99 })
100 100
101 101 return render('/index.html')
102 102
103 103 def repo_switcher(self):
104 104 if request.is_xhr:
105 105 all_repos = Repository.query().order_by(Repository.repo_name).all()
106 106 c.repos_list = self.scm_model.get_repos(all_repos,
107 107 sort_key='name_sort',
108 108 simple=True)
109 109 return render('/repo_switcher_list.html')
110 110 else:
111 return HTTPBadRequest()
111 raise HTTPBadRequest()
112 112
113 113 def branch_tag_switcher(self, repo_name):
114 114 if request.is_xhr:
115 115 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
116 116 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
117 117 return render('/switch_to_list.html')
118 118 else:
119 return HTTPBadRequest()
119 raise HTTPBadRequest()
General Comments 0
You need to be logged in to leave comments. Login now