Mercurial > public > src > rhodecode
comparison pylons_app/controllers/hg.py @ 57:e96bc5a01490
Implemented main page sorting
author | Marcin Kuzminski <marcin@python-blog.com> |
---|---|
date | Fri, 09 Apr 2010 01:42:48 +0200 |
parents | bf1b64046c79 |
children | 8fb1abd4178a |
comparison
equal
deleted
inserted
replaced
56:bf1b64046c79 | 57:e96bc5a01490 |
---|---|
13 except ImportError: | 13 except ImportError: |
14 print 'You have to import vcs module' | 14 print 'You have to import vcs module' |
15 from mercurial.util import matchdate, Abort, makedate | 15 from mercurial.util import matchdate, Abort, makedate |
16 from mercurial.hgweb.common import get_contact | 16 from mercurial.hgweb.common import get_contact |
17 from mercurial.templatefilters import age | 17 from mercurial.templatefilters import age |
18 from operator import itemgetter | |
18 log = logging.getLogger(__name__) | 19 log = logging.getLogger(__name__) |
19 | 20 |
20 class HgController(BaseController): | 21 class HgController(BaseController): |
21 | 22 |
22 def __before__(self): | 23 def __before__(self): |
23 c.repos_prefix = config['repos_name'] | 24 c.repos_prefix = config['repos_name'] |
24 c.staticurl = g.statics | 25 c.staticurl = g.statics |
25 | 26 |
26 def index(self): | 27 def index(self): |
27 c.repos_list = [] | 28 c.repos_list = [] |
29 c.current_sort = request.GET.get('sort', 'name') | |
28 | 30 |
29 def get_mtime(spath): | 31 def get_mtime(spath): |
30 cl_path = os.path.join(spath, "00changelog.i") | 32 cl_path = os.path.join(spath, "00changelog.i") |
31 if os.path.exists(cl_path): | 33 if os.path.exists(cl_path): |
32 return os.stat(cl_path).st_mtime | 34 return os.stat(cl_path).st_mtime |
38 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: | 40 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: |
39 if i[0] in allowed or ui.configbool("web", "allow" + i[0], | 41 if i[0] in allowed or ui.configbool("web", "allow" + i[0], |
40 untrusted=True): | 42 untrusted=True): |
41 yield {"type" : i[0], "extension": i[1], | 43 yield {"type" : i[0], "extension": i[1], |
42 "node": nodeid, "url": url} | 44 "node": nodeid, "url": url} |
43 | 45 |
44 for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items(): | 46 for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items(): |
45 last_change = (get_mtime(r.spath), makedate()[1]) | 47 last_change = (get_mtime(r.spath), makedate()[1]) |
46 tip = r.changectx('tip') | 48 tip = r.changectx('tip') |
47 tmp_d = {} | 49 tmp_d = {} |
48 tmp_d['name'] = name | 50 tmp_d['name'] = name |
49 tmp_d['desc'] = r.ui.config('web', 'description', 'Unknown', untrusted=True) | 51 tmp_d['name_sort'] = tmp_d['name'] |
52 tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True) | |
53 tmp_d['description_sort'] = tmp_d['description'] | |
50 tmp_d['last_change'] = age(last_change) | 54 tmp_d['last_change'] = age(last_change) |
55 tmp_d['last_change_sort'] = last_change[1] - last_change[0] | |
51 tmp_d['tip'] = str(tip) | 56 tmp_d['tip'] = str(tip) |
57 tmp_d['tip_sort'] = tip.rev() | |
52 tmp_d['rev'] = tip.rev() | 58 tmp_d['rev'] = tip.rev() |
53 tmp_d['contact'] = get_contact(r.ui.config) | 59 tmp_d['contact'] = get_contact(r.ui.config) |
60 tmp_d['contact_sort'] = get_contact(r.ui.config) | |
54 tmp_d['repo_archives'] = archivelist(r.ui, "tip", 'sa') | 61 tmp_d['repo_archives'] = archivelist(r.ui, "tip", 'sa') |
55 | 62 |
56 c.repos_list.append(tmp_d) | 63 c.repos_list.append(tmp_d) |
64 | |
65 cs = c.current_sort | |
66 c.cs_slug = cs.replace('-', '') | |
67 sortables = ['name', 'description', 'last_change', 'tip', 'contact'] | |
68 | |
69 if cs and c.cs_slug in sortables: | |
70 sort_key = c.cs_slug + '_sort' | |
71 if cs.startswith('-'): | |
72 c.repos_list.sort(key=itemgetter(sort_key), reverse=True) | |
73 else: | |
74 c.repos_list.sort(key=itemgetter(sort_key), reverse=False) | |
75 | |
57 return render('/index.html') | 76 return render('/index.html') |
58 | 77 |
59 def view(self, *args, **kwargs): | 78 def view(self, *args, **kwargs): |
60 #TODO: reimplement this not tu use hgwebdir | 79 #TODO: reimplement this not tu use hgwebdir |
61 response = g.hgapp(request.environ, self.start_response) | 80 response = g.hgapp(request.environ, self.start_response) |