comparison pylons_app/lib/base.py @ 107:5e2470ebdbc6

Added repo switcher, in base and long term caching for this.
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 26 Apr 2010 00:38:53 +0200
parents a699c0088344
children 79a4f9f1cbd6
comparison
equal deleted inserted replaced
106:a86c8de926b4 107:5e2470ebdbc6
3 Provides the BaseController class for subclassing. 3 Provides the BaseController class for subclassing.
4 """ 4 """
5 from pylons.controllers import WSGIController 5 from pylons.controllers import WSGIController
6 from pylons.templating import render_mako as render 6 from pylons.templating import render_mako as render
7 from pylons_app.model import meta 7 from pylons_app.model import meta
8 from beaker.cache import cache_region
9 from pylons import tmpl_context as c
10 from pylons_app.model.hg_model import HgModel
8 11
9 class BaseController(WSGIController): 12 class BaseController(WSGIController):
10 13 def _load_repos(self):
14
15 @cache_region('long_term', 'repo_list_2')
16 def _get_repos():
17 return [rep['name'] for rep in HgModel().get_repos()]
18
19 c.repo_list = _get_repos()
20
11 def __call__(self, environ, start_response): 21 def __call__(self, environ, start_response):
12 """Invoke the Controller""" 22 """Invoke the Controller"""
13 # WSGIController.__call__ dispatches to the Controller method 23 # WSGIController.__call__ dispatches to the Controller method
14 # the request is routed to. This routing information is 24 # the request is routed to. This routing information is
15 # available in environ['pylons.routes_dict'] 25 # available in environ['pylons.routes_dict']
26 self._load_repos()
16 try: 27 try:
17 return WSGIController.__call__(self, environ, start_response) 28 return WSGIController.__call__(self, environ, start_response)
18 finally: 29 finally:
19 meta.Session.remove() 30 meta.Session.remove()