annotate pylons_app/controllers/hg.py @ 54:fdf6dc356d45

template fix
author marcink
date Thu, 08 Apr 2010 18:17:28 +0200
parents 2e1247e62c5b
children e00dccb6f211
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 #!/usr/bin/python
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2 # -*- coding: utf-8 -*-
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 import logging
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
4 from pylons_app.lib.base import BaseController
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
5 from pylons import tmpl_context as c, app_globals as g, session, request, config
22
3142616771cd Removed default contact name
Marcin Kuzminski
parents: 21
diff changeset
6 from pylons_app.lib import helpers as h
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 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
8 from pylons.controllers.util import abort
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
9
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
10 log = logging.getLogger(__name__)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
12 class HgController(BaseController):
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
13
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
14 def __before__(self):
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
15 c.repos_prefix = config['repos_name']
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
16
8
3092016c6d0c Changed to webapp, removed get from routes,
Marcin Kuzminski
parents: 6
diff changeset
17 def view(self, *args, **kwargs):
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
18 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
19
707dfdb1c7a8 Bugfix when client is using old mercurial version and not setting http accept
marcink
parents: 32
diff changeset
20 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
21 if not http_accept:
707dfdb1c7a8 Bugfix when client is using old mercurial version and not setting http accept
marcink
parents: 32
diff changeset
22 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
23
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
24 #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
25 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
26 request.environ['PATH_INFO'].find('raw-file') != -1:
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
27 return response
32
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
28 try:
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
29 tmpl = u''.join(response)
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
30 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
31 .config['pylons.app_globals'].mako_lookup)
32
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
32
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
33 except (RuntimeError, UnicodeDecodeError):
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
34 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
35 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
36 tmpl = ''.join(response)
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
37 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
38 .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
39
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
40
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
41 return template.render(g=g, c=c, session=session, h=h)