Mercurial > kallithea
annotate pylons_app/controllers/hg.py @ 65:3f65447f6c02
Small fix for data display
author | Marcin Kuzminski <marcin@python-blog.com> |
---|---|
date | Sat, 10 Apr 2010 16:45:13 +0200 |
parents | 8fb1abd4178a |
children | cdf4fda66dd9 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 import logging | |
55
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
4 import os |
43 | 5 from pylons_app.lib.base import BaseController |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
6 from pylons import tmpl_context as c, app_globals as g, session, request, config |
22 | 7 from pylons_app.lib import helpers as h |
0 | 8 from mako.template import Template |
37
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
9 from pylons.controllers.util import abort |
55
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
10 from pylons_app.lib.base import BaseController, render |
57
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
11 from operator import itemgetter |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
57
diff
changeset
|
12 |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
57
diff
changeset
|
13 from pylons_app.model.hg_model import HgModel |
10
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
8
diff
changeset
|
14 log = logging.getLogger(__name__) |
0 | 15 |
16 class HgController(BaseController): | |
21 | 17 |
18 def __before__(self): | |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
19 c.repos_prefix = config['repos_name'] |
55
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
20 c.staticurl = g.statics |
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
21 |
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
22 def index(self): |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
57
diff
changeset
|
23 hg_model = HgModel() |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
57
diff
changeset
|
24 c.repos_list = list(hg_model.get_repos()) |
57
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
25 c.current_sort = request.GET.get('sort', 'name') |
55
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
26 |
57
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
27 cs = c.current_sort |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
28 c.cs_slug = cs.replace('-', '') |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
29 sortables = ['name', 'description', 'last_change', 'tip', 'contact'] |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
30 |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
31 if cs and c.cs_slug in sortables: |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
32 sort_key = c.cs_slug + '_sort' |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
33 if cs.startswith('-'): |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
34 c.repos_list.sort(key=itemgetter(sort_key), reverse=True) |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
35 else: |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
36 c.repos_list.sort(key=itemgetter(sort_key), reverse=False) |
e96bc5a01490
Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents:
56
diff
changeset
|
37 |
55
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
38 return render('/index.html') |
21 | 39 |
8 | 40 def view(self, *args, **kwargs): |
55
e00dccb6f211
Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
41 #TODO: reimplement this not tu use hgwebdir |
21 | 42 response = g.hgapp(request.environ, self.start_response) |
37
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
43 |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
44 http_accept = request.environ.get('HTTP_ACCEPT', False) |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
45 if not http_accept: |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
46 return abort(status_code=400, detail='no http accept in header') |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
47 |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
48 #for mercurial protocols and raw files we can't wrap into mako |
37
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
49 if http_accept.find("mercurial") != -1 or \ |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
50 request.environ['PATH_INFO'].find('raw-file') != -1: |
21 | 51 return response |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
52 try: |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
53 tmpl = u''.join(response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
54 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
55 .config['pylons.app_globals'].mako_lookup) |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
56 |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
57 except (RuntimeError, UnicodeDecodeError): |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
58 log.info('disabling unicode due to encoding error') |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
59 response = g.hgapp(request.environ, self.start_response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
60 tmpl = ''.join(response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
61 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
62 .config['pylons.app_globals'].mako_lookup, disable_unicode=True) |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
63 |
21 | 64 |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
22
diff
changeset
|
65 return template.render(g=g, c=c, session=session, h=h) |