]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
Copy over some changes to the stock template from BlueRhapsody
authorEvan Broder <broder@mit.edu>
Sat, 12 Jul 2008 23:31:34 +0000 (23:31 +0000)
committerEvan Broder <broder@mit.edu>
Sat, 12 Jul 2008 23:31:34 +0000 (23:31 +0000)
bluechips/config/middleware.py
bluechips/config/routing.py
bluechips/lib/base.py
bluechips/lib/helpers.py

index 4f9801cb6a14a6893154bedc77963e913ddbc36c..e3cd2da6f9021ea54572be0a5066200915c77d07 100644 (file)
@@ -9,6 +9,9 @@ from pylons.middleware import ErrorHandler, StaticJavascripts, \
     StatusCodeRedirect
 from pylons.wsgiapp import PylonsApp
 from routes.middleware import RoutesMiddleware
     StatusCodeRedirect
 from pylons.wsgiapp import PylonsApp
 from routes.middleware import RoutesMiddleware
+from paste import httpexceptions
+
+from tw.api import make_middleware
 
 from bluechips.config.environment import load_environment
 
 
 from bluechips.config.environment import load_environment
 
@@ -37,12 +40,19 @@ def make_app(global_conf, full_stack=True, **app_conf):
     app = PylonsApp()
     
     # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
     app = PylonsApp()
     
     # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
+    app = httpexceptions.make_middleware(app, global_conf)
     
     # Routing/Session/Cache Middleware
     app = RoutesMiddleware(app, config['routes.map'])
     app = SessionMiddleware(app, config)
     app = CacheMiddleware(app, config)
     
     
     # Routing/Session/Cache Middleware
     app = RoutesMiddleware(app, config['routes.map'])
     app = SessionMiddleware(app, config)
     app = CacheMiddleware(app, config)
     
+    app = make_middleware(app, {
+            'toscawidgets.framework': 'pylons',
+            'toscawidgets.framework.default_view': 'mako',
+            'toscawidgets.middleware.inject_resources': True
+            })
+    
     if asbool(full_stack):
         # Handle Python exceptions
         app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
     if asbool(full_stack):
         # Handle Python exceptions
         app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
@@ -59,7 +69,6 @@ def make_app(global_conf, full_stack=True, **app_conf):
 
     # Static files (If running in production, and Apache or another web 
     # server is handling this static content, remove the following 3 lines)
 
     # Static files (If running in production, and Apache or another web 
     # server is handling this static content, remove the following 3 lines)
-    javascripts_app = StaticJavascripts()
     static_app = StaticURLParser(config['pylons.paths']['static_files'])
     static_app = StaticURLParser(config['pylons.paths']['static_files'])
-    app = Cascade([static_app, javascripts_app, app])
+    app = Cascade([static_app, app])
     return app
     return app
index e860dd006dcd30b13c5b64db3608c9bd8bc6d233..199a1b42f4e88846a142887a1119c69ee332637c 100644 (file)
@@ -19,8 +19,9 @@ def make_map():
 
     # CUSTOM ROUTES HERE
 
 
     # CUSTOM ROUTES HERE
 
-    map.connect('/:controller/index', action='index')
-    map.connect('/:controller/:action/')
+    map.connect('/:controller')
+    map.connect('/:controller/', action='index')
+    map.connect('/:controller/:action')
     map.connect('/:controller/:action/:id')
 
     return map
     map.connect('/:controller/:action/:id')
 
     return map
index d33cfc2034b901e29bfa09a2b895270045c538a8..260943f78f2d1dc75aab627c16634d59d6f7393b 100644 (file)
@@ -2,11 +2,19 @@
 
 Provides the BaseController class for subclassing.
 """
 
 Provides the BaseController class for subclassing.
 """
+from pylons import tmpl_context as c
 from pylons.controllers import WSGIController
 from pylons.controllers import WSGIController
-from pylons.templating import render_mako as render
+from pylons.i18n import _, ungettext, N_
 
 
+from tw.mods.pylonshf import render, render_response, validate
+
+import bluechips.lib.helpers as h
+from bluechips import model
 from bluechips.model import meta
 
 from bluechips.model import meta
 
+from paste.request import construct_url
+from paste.httpexceptions import HTTPMovedPermanently
+
 class BaseController(WSGIController):
 
     def __call__(self, environ, start_response):
 class BaseController(WSGIController):
 
     def __call__(self, environ, start_response):
@@ -14,8 +22,18 @@ class BaseController(WSGIController):
         # WSGIController.__call__ dispatches to the Controller method
         # the request is routed to. This routing information is
         # available in environ['pylons.routes_dict']
         # WSGIController.__call__ dispatches to the Controller method
         # the request is routed to. This routing information is
         # available in environ['pylons.routes_dict']
+        if environ['pylons.routes_dict']['controller'] != 'error':
+            if environ['PATH_INFO'].endswith('/index'):
+                environ['PATH_INFO'] = environ['PATH_INFO'][:-5]
+                raise HTTPMovedPermanently(construct_url(environ))
+            if not environ['PATH_INFO'].endswith('/') and \
+                    environ['pylons.routes_dict']['action'] is 'index':
+                environ['PATH_INFO'] += '/'
+                raise HTTPMovedPermanently(construct_url(environ))
         try:
             return WSGIController.__call__(self, environ, start_response)
         finally:
             meta.Session.remove()
         try:
             return WSGIController.__call__(self, environ, start_response)
         finally:
             meta.Session.remove()
-        
\ No newline at end of file
+
+__all__ = ['c', 'h', 'render', 'render_response', 'validate',
+           'model', 'meta', '_', 'ungettext', 'N_', 'BaseController']
index 0eb7c8fccaf827c20e2853b4d6b0eba55525a5a1..864d2d68b9fac6992384a900ab2fa8ef919e3428 100644 (file)
@@ -3,4 +3,9 @@
 Consists of functions to typically be used within templates, but also
 available to Controllers. This module is available to both as 'h'.
 """
 Consists of functions to typically be used within templates, but also
 available to Controllers. This module is available to both as 'h'.
 """
-from webhelpers import *
+from routes import url_for, redirect_to
+from webhelpers.html import escape, literal, url_escape
+from webhelpers.html.tags import *
+
+def bluechips():
+    return '<span class="bluechips">BlueChips</span>'