annotate pylons_app/controllers/hg.py @ 80:928416088790

reimplemented summary page, added few filters, removed age from models and made it as filter.
author Marcin Kuzminski <marcin@python-blog.com>
date Sat, 17 Apr 2010 22:17:17 +0200
parents 71401840ed86
children 670713507d03
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
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
4 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
5 from pylons_app.lib import helpers as h
76
71401840ed86 refactoring update
Marcin Kuzminski <marcin@python-blog.com>
parents: 74
diff changeset
6 from pylons_app.lib.base import BaseController, render
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
76
71401840ed86 refactoring update
Marcin Kuzminski <marcin@python-blog.com>
parents: 74
diff changeset
9
57
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
10 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
11 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
12 log = logging.getLogger(__name__)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 class HgController(BaseController):
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
15
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
16 def __before__(self):
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
17 c.repos_prefix = config['repos_name']
55
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
18 c.staticurl = g.statics
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
19
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
20 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
21 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
22 c.repos_list = list(hg_model.get_repos())
57
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
23 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
24
57
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
25 cs = c.current_sort
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
26 c.cs_slug = cs.replace('-', '')
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
27 sortables = ['name', 'description', 'last_change', 'tip', 'contact']
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
28
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
29 if cs and c.cs_slug in sortables:
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
30 sort_key = c.cs_slug + '_sort'
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
31 if cs.startswith('-'):
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
32 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
33 else:
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=False)
e96bc5a01490 Implemented main page sorting
Marcin Kuzminski <marcin@python-blog.com>
parents: 56
diff changeset
35
55
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
36 return render('/index.html')
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
37
8
3092016c6d0c Changed to webapp, removed get from routes,
Marcin Kuzminski
parents: 6
diff changeset
38 def view(self, *args, **kwargs):
55
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
39 #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
40
80
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 76
diff changeset
41 #patch for replacing mercurial servings with hg_app servings
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 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
43 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
44 return vcs_impl
80
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 76
diff changeset
45
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 76
diff changeset
46
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
47 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
48
707dfdb1c7a8 Bugfix when client is using old mercurial version and not setting http accept
marcink
parents: 32
diff changeset
49 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
50 if not http_accept:
707dfdb1c7a8 Bugfix when client is using old mercurial version and not setting http accept
marcink
parents: 32
diff changeset
51 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
52
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
53 #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
54 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
55 request.environ['PATH_INFO'].find('raw-file') != -1:
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
56 return response
32
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
57 try:
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
58 tmpl = u''.join(response)
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
59 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
60 .config['pylons.app_globals'].mako_lookup)
32
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
61
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
62 except (RuntimeError, UnicodeDecodeError):
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
63 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
64 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
65 tmpl = ''.join(response)
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
66 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 37
diff changeset
67 .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
68
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 20
diff changeset
69
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
70 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
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
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 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84 c.repo_changesets = c.repo_info.get_changesets(10)
80
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 76
diff changeset
85 # c.repo_tags = c.repo_info.get_tags(limit=10)
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 76
diff changeset
86 # c.repo_branches = c.repo_info.get_branches(limit=10)
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
87 return render('/summary.html')
80
928416088790 reimplemented summary page,
Marcin Kuzminski <marcin@python-blog.com>
parents: 76
diff changeset
88