Skip to content

Commit

Permalink
Setup templates to configure cache without middleware
Browse files Browse the repository at this point in the history
--HG--
branch : 0.10
  • Loading branch information
bbangert committed Nov 20, 2009
1 parent 9e8a199 commit c50b0c8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pylons/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def add_template_engine(self, engine, root, options=None, alias=None):
config.template_engines.append(old_default)
"""
warnings.warn("add_template_engine is deprecated, use custom render"
" functions instead", DeprecationWarning, 3)
if not options:
options = self['buffet.template_options']
config = dict(engine=engine, template_root=root,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def load_environment(global_conf, app_conf):
config['routes.map'] = make_map(config)
config['pylons.app_globals'] = app_globals.Globals(config)
config['pylons.h'] = {{package}}.lib.helpers

# Setup cache object as early as possible
import pylons
pylons.cache._push_object(config['pylons.app_globals'].cache)

{{if template_engine == 'mako'}}

# Create the Mako TemplateLookup, with the default auto-escaping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Pylons middleware initialization"""
from beaker.middleware import CacheMiddleware, SessionMiddleware
from beaker.middleware import SessionMiddleware
from paste.cascade import Cascade
from paste.registry import RegistryManager
from paste.urlparser import StaticURLParser
Expand Down Expand Up @@ -42,7 +42,6 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
# Routing/Session/Cache Middleware
app = RoutesMiddleware(app, config['routes.map'])
app = SessionMiddleware(app, config)
app = CacheMiddleware(app, config)

# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""The application's Globals object"""

from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options

class Globals(object):

"""Globals acts as a container for objects available throughout the
Expand All @@ -13,3 +16,4 @@ class Globals(object):
'app_globals' variable

"""
self.cache = CacheManager(**parse_cache_config_options(config))
6 changes: 4 additions & 2 deletions pylons/templates/minimal_project/+package+/wsgiapp.py_tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""The {{project}} WSGI application"""
import os

from beaker.middleware import CacheMiddleware, SessionMiddleware
from beaker.cache import CacheManager
from beaker.middleware import SessionMiddleware
from beaker.util import parse_cache_config_options
{{if template_engine == 'mako'}}
from mako.lookup import TemplateLookup
{{elif template_engine == 'genshi'}}
Expand Down Expand Up @@ -104,7 +106,6 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
# Routing/Session/Cache Middleware
app = RoutesMiddleware(app, config['routes.map'])
app = SessionMiddleware(app, config)
app = CacheMiddleware(app, config)

# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)

Expand Down Expand Up @@ -144,3 +145,4 @@ class Globals(object):
'app_globals' variable

"""
self.cache = CacheManager(**parse_cache_config_options(config))
23 changes: 16 additions & 7 deletions tests/test_webapps/filestotest/app_globals.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
"""The application's Globals object"""

from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options

class Globals(object):

"""Globals acts as a container for objects available throughout the
life of the application
"""

def __init__(self, config):
"""One instance of Globals is created during application
initialization and is available during requests via the
'app_globals' variable
"""
self.message = 'Hello'
self.counter = 0

def __del__(self):
"""
Put any cleanup code to be run when the application finally exits
here.
"""
pass
self.cache = CacheManager(**parse_cache_config_options(config))

0 comments on commit c50b0c8

Please sign in to comment.