##// END OF EJS Templates
parse metatags for lightweight dashboard
marcink -
r3007:b13ca18a beta
parent child Browse files
Show More
@@ -1,119 +1,125
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
31
32 import rhodecode
32 import rhodecode
33 from rhodecode.lib import helpers as h
33 from rhodecode.lib import helpers as h
34 from rhodecode.lib.ext_json import json
34 from rhodecode.lib.ext_json import json
35 from rhodecode.lib.auth import LoginRequired
35 from rhodecode.lib.auth import LoginRequired
36 from rhodecode.lib.base import BaseController, render
36 from rhodecode.lib.base import BaseController, render
37 from rhodecode.model.db import Repository
37 from rhodecode.model.db import Repository
38 from sqlalchemy.sql.expression import func
38 from sqlalchemy.sql.expression import func
39
39
40 log = logging.getLogger(__name__)
40 log = logging.getLogger(__name__)
41
41
42
42
43 class HomeController(BaseController):
43 class HomeController(BaseController):
44
44
45 @LoginRequired()
45 @LoginRequired()
46 def __before__(self):
46 def __before__(self):
47 super(HomeController, self).__before__()
47 super(HomeController, self).__before__()
48
48
49 def index(self):
49 def index(self):
50 c.groups = self.scm_model.get_repos_groups()
50 c.groups = self.scm_model.get_repos_groups()
51 c.group = None
51 c.group = None
52
52
53 if c.visual.lightweight_dashboard is False:
53 if c.visual.lightweight_dashboard is False:
54 c.repos_list = self.scm_model.get_repos()
54 c.repos_list = self.scm_model.get_repos()
55 ## lightweight version of dashboard
55 ## lightweight version of dashboard
56 else:
56 else:
57 c.repos_list = Repository.query()\
57 c.repos_list = Repository.query()\
58 .filter(Repository.group_id == None)\
58 .filter(Repository.group_id == None)\
59 .order_by(func.lower(Repository.repo_name))\
59 .order_by(func.lower(Repository.repo_name))\
60 .all()
60 .all()
61 repos_data = []
61 repos_data = []
62 total_records = len(c.repos_list)
62 total_records = len(c.repos_list)
63
63
64 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
64 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
65 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
65 template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
66
66
67 quick_menu = lambda repo_name: (template.get_def("quick_menu")
67 quick_menu = lambda repo_name: (template.get_def("quick_menu")
68 .render(repo_name, _=_, h=h, c=c))
68 .render(repo_name, _=_, h=h, c=c))
69 repo_lnk = lambda name, rtype, private, fork_of: (
69 repo_lnk = lambda name, rtype, private, fork_of: (
70 template.get_def("repo_name")
70 template.get_def("repo_name")
71 .render(name, rtype, private, fork_of, short_name=False,
71 .render(name, rtype, private, fork_of, short_name=False,
72 admin=False, _=_, h=h, c=c))
72 admin=False, _=_, h=h, c=c))
73 last_change = lambda last_change: (template.get_def("last_change")
73 last_change = lambda last_change: (template.get_def("last_change")
74 .render(last_change, _=_, h=h, c=c))
74 .render(last_change, _=_, h=h, c=c))
75 rss_lnk = lambda repo_name: (template.get_def("rss")
75 rss_lnk = lambda repo_name: (template.get_def("rss")
76 .render(repo_name, _=_, h=h, c=c))
76 .render(repo_name, _=_, h=h, c=c))
77 atom_lnk = lambda repo_name: (template.get_def("atom")
77 atom_lnk = lambda repo_name: (template.get_def("atom")
78 .render(repo_name, _=_, h=h, c=c))
78 .render(repo_name, _=_, h=h, c=c))
79
79
80 def desc(desc):
81 if c.visual.stylify_metatags:
82 return h.urlify_text(h.desc_stylize(h.truncate(desc, 60)))
83 else:
84 return h.urlify_text(h.truncate(desc, 60))
85
80 for repo in c.repos_list:
86 for repo in c.repos_list:
81 repos_data.append({
87 repos_data.append({
82 "menu": quick_menu(repo.repo_name),
88 "menu": quick_menu(repo.repo_name),
83 "raw_name": repo.repo_name.lower(),
89 "raw_name": repo.repo_name.lower(),
84 "name": repo_lnk(repo.repo_name, repo.repo_type,
90 "name": repo_lnk(repo.repo_name, repo.repo_type,
85 repo.private, repo.fork),
91 repo.private, repo.fork),
86 "last_change": last_change(repo.last_db_change),
92 "last_change": last_change(repo.last_db_change),
87 "desc": repo.description,
93 "desc": desc(repo.description),
88 "owner": h.person(repo.user.username),
94 "owner": h.person(repo.user.username),
89 "rss": rss_lnk(repo.repo_name),
95 "rss": rss_lnk(repo.repo_name),
90 "atom": atom_lnk(repo.repo_name),
96 "atom": atom_lnk(repo.repo_name),
91 })
97 })
92
98
93 c.data = json.dumps({
99 c.data = json.dumps({
94 "totalRecords": total_records,
100 "totalRecords": total_records,
95 "startIndex": 0,
101 "startIndex": 0,
96 "sort": "name",
102 "sort": "name",
97 "dir": "asc",
103 "dir": "asc",
98 "records": repos_data
104 "records": repos_data
99 })
105 })
100
106
101 return render('/index.html')
107 return render('/index.html')
102
108
103 def repo_switcher(self):
109 def repo_switcher(self):
104 if request.is_xhr:
110 if request.is_xhr:
105 all_repos = Repository.query().order_by(Repository.repo_name).all()
111 all_repos = Repository.query().order_by(Repository.repo_name).all()
106 c.repos_list = self.scm_model.get_repos(all_repos,
112 c.repos_list = self.scm_model.get_repos(all_repos,
107 sort_key='name_sort',
113 sort_key='name_sort',
108 simple=True)
114 simple=True)
109 return render('/repo_switcher_list.html')
115 return render('/repo_switcher_list.html')
110 else:
116 else:
111 raise HTTPBadRequest()
117 raise HTTPBadRequest()
112
118
113 def branch_tag_switcher(self, repo_name):
119 def branch_tag_switcher(self, repo_name):
114 if request.is_xhr:
120 if request.is_xhr:
115 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
121 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
116 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
122 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
117 return render('/switch_to_list.html')
123 return render('/switch_to_list.html')
118 else:
124 else:
119 raise HTTPBadRequest()
125 raise HTTPBadRequest()
General Comments 0
You need to be logged in to leave comments. Login now