Mercurial > kallithea
annotate pylons_app/lib/base.py @ 200:b48ebda822a4
removed unneded imports from auth
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 22 May 2010 20:48:05 +0200 |
parents | 568f95056716 |
children | fdcef6ea3b55 |
rev | line source |
---|---|
0 | 1 """The base Controller API |
2 | |
3 Provides the BaseController class for subclassing. | |
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 | 7 from pylons.controllers import WSGIController |
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 | 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 | 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 | 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 | 33 def __call__(self, environ, start_response): |
34 """Invoke the Controller""" | |
35 # WSGIController.__call__ dispatches to the Controller method | |
36 # the request is routed to. This routing information is | |
37 # available in environ['pylons.routes_dict'] | |
38 try: | |
39 return WSGIController.__call__(self, environ, start_response) | |
40 finally: | |
51 | 41 meta.Session.remove() |