diff pylons_app/config/middleware.py @ 43:2e1247e62c5b

changed for pylons 0.1 / 1.0 added admin controller
author marcink
date Wed, 07 Apr 2010 15:28:50 +0200
parents 71ffa932799d
children 9db7782727b3
line wrap: on
line diff
--- a/pylons_app/config/middleware.py	Wed Apr 07 13:24:46 2010 +0200
+++ b/pylons_app/config/middleware.py	Wed Apr 07 15:28:50 2010 +0200
@@ -1,10 +1,9 @@
 """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
 from paste.deploy.converters import asbool
-from pylons import config
 from pylons.middleware import ErrorHandler, StatusCodeRedirect
 from pylons.wsgiapp import PylonsApp
 from routes.middleware import RoutesMiddleware
@@ -12,7 +11,7 @@
 from pylons_app.config.environment import load_environment
 from pylons_app.lib.auth import authfunc 
 
-def make_app(global_conf, full_stack=True, **app_conf):
+def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
     """Create a Pylons WSGI application and return it
 
     ``global_conf``
@@ -32,17 +31,17 @@
 
     """
     # Configure the Pylons environment
-    load_environment(global_conf, app_conf)
+    config = load_environment(global_conf, app_conf)
+
 
     # The Pylons WSGI app
-    app = PylonsApp()
+    app = PylonsApp(config=config)
 
     # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
 
     # Routing/Session/Cache Middleware
     app = RoutesMiddleware(app, config['routes.map'])
     app = SessionMiddleware(app, config)
-    app = CacheMiddleware(app, config)
     app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc)
     
     if asbool(full_stack):
@@ -53,16 +52,19 @@
         # 500 when debug is disabled)
         if asbool(config['debug']):
             #don't handle 404, since mercurial does it for us.
-            app = StatusCodeRedirect(app, [400, 401, 403, 500])
+            app = StatusCodeRedirect(app, [400, 401, 403])
         else:
             app = StatusCodeRedirect(app, [400, 401, 403, 500])
     
     # Establish the Registry for this application
     app = RegistryManager(app)
 
-    # Static files (If running in production, and Apache or another web
-    # server is handling this static content, remove the following 3 lines)
-    static_app = StaticURLParser(config['pylons.paths']['static_files'])
-    app = Cascade([static_app, app])
+    if asbool(static_files):
+        # Serve static files
+        static_app = StaticURLParser(config['pylons.paths']['static_files'])
+        app = Cascade([static_app, app])
+    
+        app.config = config
+
     return app