Changeset 3247
- Timestamp:
- 07/10/07 11:33:54 (1 year ago)
- Files:
-
- trunk/tg/templates/turbogears/+package+/config/environment.py_tmpl (modified) (2 diffs)
- trunk/tg/templates/turbogears/+package+/config/middleware.py_tmpl (modified) (3 diffs)
- trunk/tg/templates/turbogears/+package+/config/routing.py_tmpl (modified) (1 diff)
- trunk/tg/templates/turbogears/+package+/controllers/template.py_tmpl (modified) (1 diff)
- trunk/tg/templates/turbogears/+package+/docs (deleted)
- trunk/tg/templates/turbogears/+package+/i18n (deleted)
- trunk/tg/templates/turbogears/+package+/lib/app_globals.py_tmpl (modified) (1 diff)
- trunk/tg/templates/turbogears/+package+/lib/base.py_tmpl (modified) (1 diff)
- trunk/tg/templates/turbogears/+package+/templates/index.html (modified) (1 diff)
- trunk/tg/templates/turbogears/+package+/websetup.py_tmpl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tg/templates/turbogears/+package+/config/environment.py_tmpl
r3211 r3247 1 """Pylons environment configuration""" 1 2 import os 2 3 3 from paste.deploy.config import CONFIG4 5 4 from pylons import config 6 import webhelpers7 5 8 6 from ${package}.config.routing import make_map 7 import ${package}.lib.app_globals as app_globals 8 import ${package}.lib.helpers 9 9 10 10 def load_environment(global_conf, app_conf): 11 # Create our paths 12 root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 13 paths = {'root_path': root_path, 14 'controllers': os.path.join(root_path, 'controllers'), 15 'templates': [os.path.join(root_path, path) for path in \ 16 ('components', 'templates')], 17 'static_files': os.path.join(root_path, 'public') 11 # Pylons paths 12 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 13 paths = {'root_path': root, 14 'controllers': os.path.join(root, 'controllers'), 15 'templates': [os.path.join(root, 'templates')], 16 'static_files': os.path.join(root, 'public') 18 17 } 19 18 … … 22 21 template_engine='genshi', paths=paths) 23 22 24 map = make_map(config) 25 config['pylons.map'] = map 26 27 28 # Add your own template options config options here, note that all config options will override 29 # any Pylons config options 30 31 # The following template options are passed to your template engines 32 tmpl_options = {} 33 23 config['pylons.map'] = make_map() 24 config['pylons.g'] = app_globals.Globals() 25 config['pylons.h'] = ${package}.lib.helpers 26 34 27 # Load-up the template options 35 config['buffet.template_options'] = tmpl_options 36 37 # Setup the Paste CONFIG object for legacy code 38 CONFIG.push_process_config(config._current_obj()) 39 28 tmpl_options = config['buffet.template_options'] 29 30 # CONFIGURATION OPTIONS HERE (note: all config options will override any 31 # Pylons config options) trunk/tg/templates/turbogears/+package+/config/middleware.py_tmpl
r3211 r3247 1 """Pylons middleware initialization""" 1 2 from paste.cascade import Cascade 3 from paste.registry import RegistryManager 2 4 from paste.urlparser import StaticURLParser 3 from paste.registry import RegistryManager4 from paste.deploy.config import ConfigMiddleware5 5 from paste.deploy.converters import asbool 6 6 7 from pylons import config 7 8 from pylons.error import error_template 8 from pylons import config9 from pylons.middleware import ErrorHandler, ErrorDocuments,StaticJavascripts, error_mapper10 import pylons.wsgiapp9 from pylons.middleware import ErrorHandler, ErrorDocuments, \ 10 StaticJavascripts, error_mapper 11 from pylons.wsgiapp import PylonsApp 11 12 12 13 from ${package}.config.environment import load_environment … … 15 16 16 17 def make_app(global_conf, full_stack=True, **app_conf): 17 """Create a WSGI application and return it 18 19 global_conf is a dict representing the Paste configuration options, the 20 paste.deploy.converters should be used when parsing Paste config options 21 to ensure they're treated properly. 18 """Create a Pylons WSGI application and return it 19 20 `global_conf` 21 The inherited configuration for this application. Normally from the 22 [DEFAULT] section of the Paste ini file. 23 24 `full_stack` 25 Whether or not this application provides a full WSGI stack (by default 26 meaning it handles its own exceptions and errors). Disable full_stack 27 when this application is "managed" by another WSGI middleware. 28 29 `app_conf` 30 The application's local configuration. Normally specified in the 31 [app:<name>] section of the Paste ini file (where <name> defaults to 32 main). 22 33 """ 23 # Load our Pylons configuration defaults34 # Load the Pylons environment configuration 24 35 load_environment(global_conf, app_conf) 25 36 26 # Load our default Pylons WSGI app and make g available 27 app = pylons.wsgiapp.PylonsApp(helpers=${package}.lib.helpers, 28 g=app_globals.Globals) 37 # Load the Pylons WSGI app 38 app = PylonsApp() 39 40 # CUSTOM MIDDLEWARE HERE (filtered by the error handling middlewares) 29 41 30 app = ConfigMiddleware(app, config._current_obj())31 32 # YOUR MIDDLEWARE33 # Put your own middleware here, so that any problems are caught by the error34 # handling middleware underneath35 36 # If errror handling will be handled by middleware for multiple apps, you37 # will want to set full_stack = False in your config file so that it can38 # catch the problems.39 42 if asbool(full_stack): 40 # Error Handling 41 app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware']) 42 43 # Display error documents for 401, 403, 404 status codes (if debug is disabled also 44 # intercepts 500) 43 # Handle Python exceptions 44 app = ErrorHandler(app, global_conf, error_template=error_template, 45 **config['pylons.errorware']) 46 47 # Display error documents for 401, 403, 404 status codes (and 500 when 48 # debug is disabled) 45 49 app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) 46 50 … … 48 52 app = RegistryManager(app) 49 53 54 # Static files 55 javascripts_app = StaticJavascripts() 50 56 static_app = StaticURLParser(config['pylons.paths']['static_files']) 51 javascripts_app = StaticJavascripts()52 57 app = Cascade([static_app, javascripts_app, app]) 53 58 return app trunk/tg/templates/turbogears/+package+/config/routing.py_tmpl
r3211 r3247 1 """ Setup your Routes options here"""1 """Routes configuration 2 2 3 import os 4 3 The more specific and detailed routes should be defined first so they may take 4 precedent over the more generic routes. For more information refer to the 5 routes manual at http://routes.groovie.org/docs/ 6 """ 7 from pylons import config 5 8 from routes import Mapper 6 9 7 8 def make_map(conf={}): 9 10 root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 11 map = Mapper(directory=os.path.join(root_path, 'controllers')) 10 def make_map(): 11 map = Mapper(directory=config['pylons.paths']['controllers'], 12 always_scan=config['debug']) 12 13 13 14 # This route connects your root controller 14 15 map.connect('*url', controller='root', action='route') 15 16 16 # This route handles displaying the error page and graphics used in the 404/500 17 # error pages. It should likely stay at the top to ensure that the error page is 18 # displayed properly. 19 17 # The ErrorController route (handles 404/500 error pages): it should likely 18 # stay at the top to ensure that it can always be resolved 20 19 map.connect('error/:action/:id', controller='error') 21 20 22 # Define your routes. The more specific and detailed routes should be defined first, 23 # so they may take precedent over the more generic routes. For more information, refer 24 # to the routes manual @ http://routes.groovie.org/docs/ 21 # CUSTOM ROUTES HERE 25 22 26 map.connect('*url', controller='template', action='view' , _encoding=None)23 map.connect('*url', controller='template', action='view') 27 24 28 25 return map trunk/tg/templates/turbogears/+package+/controllers/template.py_tmpl
r3131 r3247 4 4 def view(self, url): 5 5 """ 6 This is the last place which is tried during a request to try to find a 7 file to serve. It could be used for example to display a template:: 6 By default the final controller tried to fulfill the request when no 7 other routes match. It may be used to display a template when all else 8 fails, e.g.:: 8 9 9 10 def view(self, url): 10 return render_response(url) 11 12 Or, if you're using Myghty and would like to catch the component not 13 found error which will occur when the template doesn't exist; you 14 can use the following version which will provide a 404 if the template 15 doesn't exist:: 16 17 import myghty.exception 11 return render_response('/%s' % url) 12 13 Or if you're using Mako and want to explicitly send a 404 (Not Found) 14 response code when the requested template doesn't exist:: 15 16 import mako.exceptions 18 17 19 18 def view(self, url): 20 19 try: 21 return render_response('/ '+url)22 except m yghty.exception.ComponentNotFound:23 return Response(code=404)20 return render_response('/%s' % url) 21 except mako.exceptions.TopLevelLookupException: 22 abort(404) 24 23 25 The default is just to abort the request with a 404 File not found 26 status message. 24 By default this controller aborts the request with a 404 (Not Found) 27 25 """ 28 26 abort(404) trunk/tg/templates/turbogears/+package+/lib/app_globals.py_tmpl
r3131 r3247 1 """Pylons application's Globals object""" 2 from pylons import config 3 1 4 class Globals(object): 2 3 def __init__(self, global_conf, app_conf, **extra): 4 """ 5 Globals acts as a container for objects available throughout 6 the life of the application. 7 8 One instance of Globals is created by Pylons during 9 application initialization and is available during requests 10 via the 'g' variable. 11 12 ``global_conf`` 13 The same variable used throughout ``config/middleware.py`` 14 namely, the variables from the ``[DEFAULT]`` section of the 15 configuration file. 16 17 ``app_conf`` 18 The same ``kw`` dictionary used throughout 19 ``config/middleware.py`` namely, the variables from the 20 section in the config file for your application. 21 22 ``extra`` 23 The configuration returned from ``load_config`` in 24 ``config/middleware.py`` which may be of use in the setup of 25 your global variables. 26 5 """Globals acts as a container for objects available throughout the life of 6 the application. 7 """ 8 def __init__(self): 9 """One instance of Globals is created during application initialization 10 and is available during requests via the 'g' variable. 27 11 """ 28 12 pass 29 30 def __del__(self):31 """32 Put any cleanup code to be run when the application finally exits33 here.34 """35 passtrunk/tg/templates/turbogears/+package+/lib/base.py_tmpl
r3131 r3247 1 from pylons import Response, c, g, cache, request, session1 from pylons import Response, c, g, cache, request, response, session 2 2 from pylons.controllers import WSGIController 3 3 from pylons.decorators import jsonify, validate trunk/tg/templates/turbogears/+package+/templates/index.html
r3199 r3247 24 24 <li><a href="http://groups.google.com/group/turbogears">Mail List</a> </li> 25 25 </ul> 26 <span py:replace="now ">now</span>26 <span py:replace="now.strftime('%Y-%m-%d %H:%M')">now</span> 27 27 </div> 28 28 <div id="getting_started"> trunk/tg/templates/turbogears/+package+/websetup.py_tmpl
r3131 r3247 1 import paste.deploy 1 from paste.deploy import appconfig 2 from pylons import config 3 4 from ${package}.config.environment import load_environment 2 5 3 6 def setup_config(command, filename, section, vars): … … 5 8 Place any commands to setup ${package} here. 6 9 """ 7 conf = paste.deploy.appconfig('config:' + filename) 8 conf.update(dict(app_conf=conf.local_conf, global_conf=conf.global_conf)) 9 paste.deploy.CONFIG.push_process_config(conf) 10 conf = appconfig('config:' + filename) 11 load_environment(conf.global_conf, conf.local_conf) 10 12