Show More
@@ -1,47 +1,39 b'' | |||||
1 | #!/usr/bin/python |
|
1 | #!/usr/bin/python | |
2 | # -*- coding: utf-8 -*- |
|
2 | # -*- coding: utf-8 -*- | |
3 | from mako.template import Template |
|
3 | import logging | |
4 | from mercurial.hg import repository |
|
|||
5 | from mercurial.hgweb import hgweb |
|
|||
6 | from mercurial.hgweb.request import wsgiapplication |
|
|||
7 | from mercurial.localrepo import localrepository |
|
|||
8 | from operator import itemgetter |
|
4 | from operator import itemgetter | |
9 |
from pylons import tmpl_context as c, |
|
5 | from pylons import tmpl_context as c, request, config | |
10 | from pylons.controllers.util import abort |
|
|||
11 | from pylons_app.lib import helpers as h |
|
|||
12 | from pylons_app.lib.base import BaseController, render |
|
6 | from pylons_app.lib.base import BaseController, render | |
13 | from pylons_app.lib.utils import get_repo_slug |
|
7 | from pylons_app.lib.utils import get_repo_slug | |
14 | from pylons_app.model.hg_model import HgModel |
|
8 | from pylons_app.model.hg_model import HgModel | |
15 | import logging |
|
|||
16 | import os |
|
|||
17 | from beaker.cache import cache_region |
|
9 | from beaker.cache import cache_region | |
18 | log = logging.getLogger(__name__) |
|
10 | log = logging.getLogger(__name__) | |
19 |
|
11 | |||
20 | class HgController(BaseController): |
|
12 | class HgController(BaseController): | |
21 |
|
13 | |||
22 | def __before__(self): |
|
14 | def __before__(self): | |
23 | c.repos_prefix = config['repos_name'] |
|
15 | c.repos_prefix = config['repos_name'] | |
24 | c.repo_name = get_repo_slug(request) |
|
16 | c.repo_name = get_repo_slug(request) | |
25 |
|
17 | |||
26 | def index(self): |
|
18 | def index(self): | |
27 |
|
19 | |||
28 | hg_model = HgModel() |
|
20 | hg_model = HgModel() | |
29 | @cache_region('short_term', 'repo_list') |
|
21 | @cache_region('short_term', 'repo_list') | |
30 | def _list(): |
|
22 | def _list(): | |
31 | return list(hg_model.get_repos()) |
|
23 | return list(hg_model.get_repos()) | |
32 |
|
24 | |||
33 | c.repos_list = _list() |
|
25 | c.repos_list = _list() | |
34 | c.current_sort = request.GET.get('sort', 'name') |
|
26 | c.current_sort = request.GET.get('sort', 'name') | |
35 |
|
27 | |||
36 | cs = c.current_sort |
|
28 | cs = c.current_sort | |
37 | c.cs_slug = cs.replace('-', '') |
|
29 | c.cs_slug = cs.replace('-', '') | |
38 | sortables = ['name', 'description', 'last_change', 'tip', 'contact'] |
|
30 | sortables = ['name', 'description', 'last_change', 'tip', 'contact'] | |
39 |
|
31 | |||
40 | if cs and c.cs_slug in sortables: |
|
32 | if cs and c.cs_slug in sortables: | |
41 | sort_key = c.cs_slug + '_sort' |
|
33 | sort_key = c.cs_slug + '_sort' | |
42 | if cs.startswith('-'): |
|
34 | if cs.startswith('-'): | |
43 | c.repos_list.sort(key=itemgetter(sort_key), reverse=True) |
|
35 | c.repos_list.sort(key=itemgetter(sort_key), reverse=True) | |
44 | else: |
|
36 | else: | |
45 | c.repos_list.sort(key=itemgetter(sort_key), reverse=False) |
|
37 | c.repos_list.sort(key=itemgetter(sort_key), reverse=False) | |
46 |
|
38 | |||
47 | return render('/index.html') |
|
39 | return render('/index.html') |
General Comments 0
You need to be logged in to leave comments.
Login now