annotate pylons_app/lib/base.py @ 169:8e01265fb586

added long term caching of repo_list to the base controller. changed hg and repos to use that cached list.
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 21 May 2010 02:17:13 +0200
parents 988477a05db6
children 3380ca40cdba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """The base Controller API
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 Provides the BaseController class for subclassing.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 """
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
5 from pylons.controllers import WSGIController
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6 from pylons.templating import render_mako as render
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 from pylons_app.model import meta
107
5e2470ebdbc6 Added repo switcher, in base and long term caching for this.
Marcin Kuzminski <marcin@python-works.com>
parents: 51
diff changeset
8 from beaker.cache import cache_region
5e2470ebdbc6 Added repo switcher, in base and long term caching for this.
Marcin Kuzminski <marcin@python-works.com>
parents: 51
diff changeset
9 from pylons import tmpl_context as c
5e2470ebdbc6 Added repo switcher, in base and long term caching for this.
Marcin Kuzminski <marcin@python-works.com>
parents: 51
diff changeset
10 from pylons_app.model.hg_model import HgModel
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11
169
8e01265fb586 added long term caching of repo_list to the base controller. changed hg and repos to use that cached list.
Marcin Kuzminski <marcin@python-works.com>
parents: 151
diff changeset
12 @cache_region('long_term', 'cached_repo_list')
8e01265fb586 added long term caching of repo_list to the base controller. changed hg and repos to use that cached list.
Marcin Kuzminski <marcin@python-works.com>
parents: 151
diff changeset
13 def _get_repos_cached():
8e01265fb586 added long term caching of repo_list to the base controller. changed hg and repos to use that cached list.
Marcin Kuzminski <marcin@python-works.com>
parents: 151
diff changeset
14 return [rep for rep in HgModel().get_repos()]
134
79a4f9f1cbd6 Moved cached function for easier invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
15
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16 class BaseController(WSGIController):
107
5e2470ebdbc6 Added repo switcher, in base and long term caching for this.
Marcin Kuzminski <marcin@python-works.com>
parents: 51
diff changeset
17
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
18 def __call__(self, environ, start_response):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 """Invoke the Controller"""
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20 # WSGIController.__call__ dispatches to the Controller method
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 # the request is routed to. This routing information is
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
22 # available in environ['pylons.routes_dict']
169
8e01265fb586 added long term caching of repo_list to the base controller. changed hg and repos to use that cached list.
Marcin Kuzminski <marcin@python-works.com>
parents: 151
diff changeset
23 c.cached_repo_list = _get_repos_cached()
151
988477a05db6 moved sqlalchemy session to base.
Marcin Kuzminski <marcin@python-works.com>
parents: 134
diff changeset
24 self.sa = meta.Session
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
25 try:
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26 return WSGIController.__call__(self, environ, start_response)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
27 finally:
51
a699c0088344 fixed sqlalchemy session bug,
marcink
parents: 17
diff changeset
28 meta.Session.remove()