##// END OF EJS Templates
parse metatags for lightweight dashboard
marcink -
r3007:b13ca18a beta
parent child Browse files
Show More
@@ -1,119 +1,125
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 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 86 for repo in c.repos_list:
81 87 repos_data.append({
82 88 "menu": quick_menu(repo.repo_name),
83 89 "raw_name": repo.repo_name.lower(),
84 90 "name": repo_lnk(repo.repo_name, repo.repo_type,
85 91 repo.private, repo.fork),
86 92 "last_change": last_change(repo.last_db_change),
87 "desc": repo.description,
93 "desc": desc(repo.description),
88 94 "owner": h.person(repo.user.username),
89 95 "rss": rss_lnk(repo.repo_name),
90 96 "atom": atom_lnk(repo.repo_name),
91 97 })
92 98
93 99 c.data = json.dumps({
94 100 "totalRecords": total_records,
95 101 "startIndex": 0,
96 102 "sort": "name",
97 103 "dir": "asc",
98 104 "records": repos_data
99 105 })
100 106
101 107 return render('/index.html')
102 108
103 109 def repo_switcher(self):
104 110 if request.is_xhr:
105 111 all_repos = Repository.query().order_by(Repository.repo_name).all()
106 112 c.repos_list = self.scm_model.get_repos(all_repos,
107 113 sort_key='name_sort',
108 114 simple=True)
109 115 return render('/repo_switcher_list.html')
110 116 else:
111 117 raise HTTPBadRequest()
112 118
113 119 def branch_tag_switcher(self, repo_name):
114 120 if request.is_xhr:
115 121 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
116 122 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
117 123 return render('/switch_to_list.html')
118 124 else:
119 125 raise HTTPBadRequest()
General Comments 0
You need to be logged in to leave comments. Login now