annotate pylons_app/lib/base.py @ 196:568f95056716

moved all cache function out to Base Controller for easier maintainance
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 May 2010 19:18:09 +0200
parents 3380ca40cdba
children fdcef6ea3b55
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 """
185
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
5 from beaker.cache import cache_region
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
6 from pylons import config, tmpl_context as c, request, session
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 from pylons.controllers import WSGIController
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8 from pylons.templating import render_mako as render
185
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
9 from pylons_app.lib.auth import LoginRequired, AuthUser
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
10 from pylons_app.lib.utils import get_repo_slug
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11 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
12 from pylons_app.model.hg_model import HgModel
185
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
13 from pylons_app import get_version
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14
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
15 @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
16 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
17 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
18
196
568f95056716 moved all cache function out to Base Controller for easier maintainance
Marcin Kuzminski <marcin@python-works.com>
parents: 185
diff changeset
19 @cache_region('long_term', 'full_changelog')
568f95056716 moved all cache function out to Base Controller for easier maintainance
Marcin Kuzminski <marcin@python-works.com>
parents: 185
diff changeset
20 def _full_changelog_cached(repo_name):
568f95056716 moved all cache function out to Base Controller for easier maintainance
Marcin Kuzminski <marcin@python-works.com>
parents: 185
diff changeset
21 return list(reversed(list(HgModel().get_repo(repo_name))))
568f95056716 moved all cache function out to Base Controller for easier maintainance
Marcin Kuzminski <marcin@python-works.com>
parents: 185
diff changeset
22
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
23 class BaseController(WSGIController):
185
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
24
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
25 def __before__(self):
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
26 c.hg_app_version = get_version()
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
27 c.repos_prefix = config['hg_app_name']
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
28 c.repo_name = get_repo_slug(request)
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
29 c.hg_app_user = session.get('hg_app_user', AuthUser())
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
30 c.cached_repo_list = _get_repos_cached()
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
31 self.sa = meta.Session
3380ca40cdba added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
Marcin Kuzminski <marcin@python-works.com>
parents: 169
diff changeset
32
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 def __call__(self, environ, start_response):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
34 """Invoke the Controller"""
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
35 # WSGIController.__call__ dispatches to the Controller method
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 # the request is routed to. This routing information is
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
37 # available in environ['pylons.routes_dict']
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38 try:
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
39 return WSGIController.__call__(self, environ, start_response)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
40 finally:
51
a699c0088344 fixed sqlalchemy session bug,
marcink
parents: 17
diff changeset
41 meta.Session.remove()