##// END OF EJS Templates
refactoring update
Marcin Kuzminski -
r76:71401840 default
parent child Browse files
Show More
@@ -1,84 +1,82 b''
1 #!/usr/bin/python
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
2 # -*- coding: utf-8 -*-
3 import logging
3 import logging
4 import os
5 from pylons_app.lib.base import BaseController
6 from pylons import tmpl_context as c, app_globals as g, session, request, config
4 from pylons import tmpl_context as c, app_globals as g, session, request, config
7 from pylons_app.lib import helpers as h
5 from pylons_app.lib import helpers as h
6 from pylons_app.lib.base import BaseController, render
8 from mako.template import Template
7 from mako.template import Template
9 from pylons.controllers.util import abort
8 from pylons.controllers.util import abort
10 from pylons_app.lib.base import BaseController, render
9
11 from operator import itemgetter
10 from operator import itemgetter
12
13 from pylons_app.model.hg_model import HgModel
11 from pylons_app.model.hg_model import HgModel
14 log = logging.getLogger(__name__)
12 log = logging.getLogger(__name__)
15
13
16 class HgController(BaseController):
14 class HgController(BaseController):
17
15
18 def __before__(self):
16 def __before__(self):
19 c.repos_prefix = config['repos_name']
17 c.repos_prefix = config['repos_name']
20 c.staticurl = g.statics
18 c.staticurl = g.statics
21
19
22 def index(self):
20 def index(self):
23 hg_model = HgModel()
21 hg_model = HgModel()
24 c.repos_list = list(hg_model.get_repos())
22 c.repos_list = list(hg_model.get_repos())
25 c.current_sort = request.GET.get('sort', 'name')
23 c.current_sort = request.GET.get('sort', 'name')
26
24
27 cs = c.current_sort
25 cs = c.current_sort
28 c.cs_slug = cs.replace('-', '')
26 c.cs_slug = cs.replace('-', '')
29 sortables = ['name', 'description', 'last_change', 'tip', 'contact']
27 sortables = ['name', 'description', 'last_change', 'tip', 'contact']
30
28
31 if cs and c.cs_slug in sortables:
29 if cs and c.cs_slug in sortables:
32 sort_key = c.cs_slug + '_sort'
30 sort_key = c.cs_slug + '_sort'
33 if cs.startswith('-'):
31 if cs.startswith('-'):
34 c.repos_list.sort(key=itemgetter(sort_key), reverse=True)
32 c.repos_list.sort(key=itemgetter(sort_key), reverse=True)
35 else:
33 else:
36 c.repos_list.sort(key=itemgetter(sort_key), reverse=False)
34 c.repos_list.sort(key=itemgetter(sort_key), reverse=False)
37
35
38 return render('/index.html')
36 return render('/index.html')
39
37
40 def view(self, *args, **kwargs):
38 def view(self, *args, **kwargs):
41 #TODO: reimplement this not tu use hgwebdir
39 #TODO: reimplement this not tu use hgwebdir
42
40
43 vcs_impl = self._get_vcs_impl(request.environ)
41 vcs_impl = self._get_vcs_impl(request.environ)
44 if vcs_impl:
42 if vcs_impl:
45 return vcs_impl
43 return vcs_impl
46 response = g.hgapp(request.environ, self.start_response)
44 response = g.hgapp(request.environ, self.start_response)
47
45
48 http_accept = request.environ.get('HTTP_ACCEPT', False)
46 http_accept = request.environ.get('HTTP_ACCEPT', False)
49 if not http_accept:
47 if not http_accept:
50 return abort(status_code=400, detail='no http accept in header')
48 return abort(status_code=400, detail='no http accept in header')
51
49
52 #for mercurial protocols and raw files we can't wrap into mako
50 #for mercurial protocols and raw files we can't wrap into mako
53 if http_accept.find("mercurial") != -1 or \
51 if http_accept.find("mercurial") != -1 or \
54 request.environ['PATH_INFO'].find('raw-file') != -1:
52 request.environ['PATH_INFO'].find('raw-file') != -1:
55 return response
53 return response
56 try:
54 try:
57 tmpl = u''.join(response)
55 tmpl = u''.join(response)
58 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
56 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
59 .config['pylons.app_globals'].mako_lookup)
57 .config['pylons.app_globals'].mako_lookup)
60
58
61 except (RuntimeError, UnicodeDecodeError):
59 except (RuntimeError, UnicodeDecodeError):
62 log.info('disabling unicode due to encoding error')
60 log.info('disabling unicode due to encoding error')
63 response = g.hgapp(request.environ, self.start_response)
61 response = g.hgapp(request.environ, self.start_response)
64 tmpl = ''.join(response)
62 tmpl = ''.join(response)
65 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
63 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
66 .config['pylons.app_globals'].mako_lookup, disable_unicode=True)
64 .config['pylons.app_globals'].mako_lookup, disable_unicode=True)
67
65
68
66
69 return template.render(g=g, c=c, session=session, h=h)
67 return template.render(g=g, c=c, session=session, h=h)
70
68
71
69
72
70
73
71
74 def _get_vcs_impl(self, environ):
72 def _get_vcs_impl(self, environ):
75 path_info = environ['PATH_INFO']
73 path_info = environ['PATH_INFO']
76 c.repo_name = path_info.split('/')[-2]
74 c.repo_name = path_info.split('/')[-2]
77 action = path_info.split('/')[-1]
75 action = path_info.split('/')[-1]
78 if not action.startswith('_'):
76 if not action.startswith('_'):
79 return False
77 return False
80 else:
78 else:
81 hg_model = HgModel()
79 hg_model = HgModel()
82 c.repo_info = hg_model.get_repo(c.repo_name)
80 c.repo_info = hg_model.get_repo(c.repo_name)
83 c.repo_changesets = c.repo_info.get_changesets(10)
81 c.repo_changesets = c.repo_info.get_changesets(10)
84 return render('/summary.html')
82 return render('/summary.html')
General Comments 0
You need to be logged in to leave comments. Login now