Mercurial > public > src > rhodecode
annotate pylons_app/controllers/hg.py @ 74:cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
author | Marcin Kuzminski <marcin@python-blog.com> |
---|---|
date | Mon, 12 Apr 2010 10:29:18 +0200 |
parents | 8fb1abd4178a |
children | 71401840ed86 |
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 |
74
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
42 |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
43 vcs_impl = self._get_vcs_impl(request.environ) |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
44 if vcs_impl: |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
45 return vcs_impl |
21 | 46 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
|
47 |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
48 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
|
49 if not http_accept: |
707dfdb1c7a8
Bugfix when client is using old mercurial version and not setting http accept
marcink
parents:
32
diff
changeset
|
50 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
|
51 |
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
|
52 #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
|
53 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
|
54 request.environ['PATH_INFO'].find('raw-file') != -1: |
21 | 55 return response |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
56 try: |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
57 tmpl = u''.join(response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
58 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
59 .config['pylons.app_globals'].mako_lookup) |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
60 |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
61 except (RuntimeError, UnicodeDecodeError): |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
62 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
|
63 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
|
64 tmpl = ''.join(response) |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
65 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
37
diff
changeset
|
66 .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
|
67 |
21 | 68 |
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
|
69 return template.render(g=g, c=c, session=session, h=h) |
74
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
70 |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
71 |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
72 |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
73 |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
74 def _get_vcs_impl(self, environ): |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
75 path_info = environ['PATH_INFO'] |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
76 c.repo_name = path_info.split('/')[-2] |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
77 action = path_info.split('/')[-1] |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
78 if not action.startswith('_'): |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
79 return False |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
80 else: |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
81 hg_model = HgModel() |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
82 c.repo_info = hg_model.get_repo(c.repo_name) |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
83 c.repo_changesets = c.repo_info.get_changesets(10) |
cdf4fda66dd9
Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents:
58
diff
changeset
|
84 return render('/summary.html') |