Mercurial > kallithea
comparison rhodecode/controllers/admin/repos_groups.py @ 2945:68e95f5ae3a7 beta
lightweight dashboard fix for repos group
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 20 Oct 2012 14:50:38 +0200 |
parents | 0959096b2c02 |
children | 9937afa7f093 |
comparison
equal
deleted
inserted
replaced
2944:0add173667b6 | 2945:68e95f5ae3a7 |
---|---|
33 from pylons.controllers.util import redirect | 33 from pylons.controllers.util import redirect |
34 from pylons.i18n.translation import _ | 34 from pylons.i18n.translation import _ |
35 | 35 |
36 from sqlalchemy.exc import IntegrityError | 36 from sqlalchemy.exc import IntegrityError |
37 | 37 |
38 import rhodecode | |
38 from rhodecode.lib import helpers as h | 39 from rhodecode.lib import helpers as h |
40 from rhodecode.lib.ext_json import json | |
39 from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator,\ | 41 from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator,\ |
40 HasReposGroupPermissionAnyDecorator | 42 HasReposGroupPermissionAnyDecorator |
41 from rhodecode.lib.base import BaseController, render | 43 from rhodecode.lib.base import BaseController, render |
42 from rhodecode.model.db import RepoGroup | 44 from rhodecode.model.db import RepoGroup, Repository |
43 from rhodecode.model.repos_group import ReposGroupModel | 45 from rhodecode.model.repos_group import ReposGroupModel |
44 from rhodecode.model.forms import ReposGroupForm | 46 from rhodecode.model.forms import ReposGroupForm |
45 from rhodecode.model.meta import Session | 47 from rhodecode.model.meta import Session |
46 from rhodecode.model.repo import RepoModel | 48 from rhodecode.model.repo import RepoModel |
47 from webob.exc import HTTPInternalServerError, HTTPNotFound | 49 from webob.exc import HTTPInternalServerError, HTTPNotFound |
48 from rhodecode.lib.utils2 import str2bool | 50 from rhodecode.lib.utils2 import str2bool |
51 from sqlalchemy.sql.expression import func | |
49 | 52 |
50 log = logging.getLogger(__name__) | 53 log = logging.getLogger(__name__) |
51 | 54 |
52 | 55 |
53 class ReposGroupsController(BaseController): | 56 class ReposGroupsController(BaseController): |
279 def show(self, id, format='html'): | 282 def show(self, id, format='html'): |
280 """GET /repos_groups/id: Show a specific item""" | 283 """GET /repos_groups/id: Show a specific item""" |
281 # url('repos_group', id=ID) | 284 # url('repos_group', id=ID) |
282 | 285 |
283 c.group = RepoGroup.get_or_404(id) | 286 c.group = RepoGroup.get_or_404(id) |
284 | |
285 c.group_repos = c.group.repositories.all() | 287 c.group_repos = c.group.repositories.all() |
286 | 288 |
287 #overwrite our cached list with current filter | 289 #overwrite our cached list with current filter |
288 gr_filter = c.group_repos | 290 gr_filter = c.group_repos |
289 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter) | |
290 | |
291 c.repos_list = c.cached_repo_list | |
292 | |
293 c.repo_cnt = 0 | 291 c.repo_cnt = 0 |
294 | 292 |
295 groups = RepoGroup.query().order_by(RepoGroup.group_name)\ | 293 groups = RepoGroup.query().order_by(RepoGroup.group_name)\ |
296 .filter(RepoGroup.group_parent_id == id).all() | 294 .filter(RepoGroup.group_parent_id == id).all() |
297 c.groups = self.scm_model.get_repos_groups(groups) | 295 c.groups = self.scm_model.get_repos_groups(groups) |
296 | |
297 if c.visual.lightweight_dashboard is False: | |
298 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter) | |
299 | |
300 c.repos_list = c.cached_repo_list | |
301 ## lightweight version of dashboard | |
302 else: | |
303 c.repos_list = Repository.query()\ | |
304 .filter(Repository.group_id == id)\ | |
305 .order_by(func.lower(Repository.repo_name))\ | |
306 .all() | |
307 repos_data = [] | |
308 total_records = len(c.repos_list) | |
309 | |
310 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup | |
311 template = _tmpl_lookup.get_template('data_table/_dt_elements.html') | |
312 | |
313 quick_menu = lambda repo_name: (template.get_def("quick_menu") | |
314 .render(repo_name, _=_, h=h, c=c)) | |
315 repo_lnk = lambda name, rtype, private, fork_of: ( | |
316 template.get_def("repo_name") | |
317 .render(name, rtype, private, fork_of, short_name=False, | |
318 admin=False, _=_, h=h, c=c)) | |
319 last_change = lambda last_change: (template.get_def("last_change") | |
320 .render(last_change, _=_, h=h, c=c)) | |
321 rss_lnk = lambda repo_name: (template.get_def("rss") | |
322 .render(repo_name, _=_, h=h, c=c)) | |
323 atom_lnk = lambda repo_name: (template.get_def("atom") | |
324 .render(repo_name, _=_, h=h, c=c)) | |
325 | |
326 for repo in c.repos_list: | |
327 repos_data.append({ | |
328 "menu": quick_menu(repo.repo_name), | |
329 "raw_name": repo.repo_name.lower(), | |
330 "name": repo_lnk(repo.repo_name, repo.repo_type, | |
331 repo.private, repo.fork), | |
332 "last_change": last_change(repo.last_db_change), | |
333 "desc": repo.description, | |
334 "owner": h.person(repo.user.username), | |
335 "rss": rss_lnk(repo.repo_name), | |
336 "atom": atom_lnk(repo.repo_name), | |
337 }) | |
338 | |
339 c.data = json.dumps({ | |
340 "totalRecords": total_records, | |
341 "startIndex": 0, | |
342 "sort": "name", | |
343 "dir": "asc", | |
344 "records": repos_data | |
345 }) | |
346 | |
298 return render('admin/repos_groups/repos_groups.html') | 347 return render('admin/repos_groups/repos_groups.html') |
299 | 348 |
300 @HasPermissionAnyDecorator('hg.admin') | 349 @HasPermissionAnyDecorator('hg.admin') |
301 def edit(self, id, format='html'): | 350 def edit(self, id, format='html'): |
302 """GET /repos_groups/id/edit: Form to edit an existing item""" | 351 """GET /repos_groups/id/edit: Form to edit an existing item""" |