Changeset 3247

Show
Ignore:
Timestamp:
07/10/07 11:33:54 (1 year ago)
Author:
fredlin
Message:

update templates to meet the recent pylons template

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tg/templates/turbogears/+package+/config/environment.py_tmpl

    r3211 r3247  
     1"""Pylons environment configuration""" 
    12import os 
    23 
    3 from paste.deploy.config import CONFIG 
    4  
    54from pylons import config 
    6 import webhelpers 
    75 
    86from ${package}.config.routing import make_map 
     7import ${package}.lib.app_globals as app_globals 
     8import ${package}.lib.helpers 
    99 
    1010def 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') 
    1817             } 
    1918         
     
    2221                    template_engine='genshi', paths=paths) 
    2322     
    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 
    3427    # 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""" 
    12from paste.cascade import Cascade 
     3from paste.registry import RegistryManager 
    24from paste.urlparser import StaticURLParser 
    3 from paste.registry import RegistryManager 
    4 from paste.deploy.config import ConfigMiddleware 
    55from paste.deploy.converters import asbool 
    66 
     7from pylons import config 
    78from pylons.error import error_template 
    8 from pylons import config 
    9 from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper 
    10 import pylons.wsgiapp 
     9from pylons.middleware import ErrorHandler, ErrorDocuments, \ 
     10 StaticJavascripts, error_mapper 
     11from pylons.wsgiapp import PylonsApp 
    1112 
    1213from ${package}.config.environment import load_environment 
     
    1516 
    1617def 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). 
    2233    """ 
    23     # Load our Pylons configuration defaults 
     34    # Load the Pylons environment configuration 
    2435    load_environment(global_conf, app_conf) 
    2536     
    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)  
    2941     
    30     app = ConfigMiddleware(app, config._current_obj()) 
    31      
    32     # YOUR MIDDLEWARE 
    33     # Put your own middleware here, so that any problems are caught by the error 
    34     # handling middleware underneath 
    35      
    36     # If errror handling will be handled by middleware for multiple apps, you 
    37     # will want to set full_stack = False in your config file so that it can 
    38     # catch the problems. 
    3942    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)  
    4549        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) 
    4650     
     
    4852    app = RegistryManager(app) 
    4953     
     54    # Static files 
     55    javascripts_app = StaticJavascripts() 
    5056    static_app = StaticURLParser(config['pylons.paths']['static_files']) 
    51     javascripts_app = StaticJavascripts() 
    5257    app = Cascade([static_app, javascripts_app, app]) 
    5358    return app 
  • trunk/tg/templates/turbogears/+package+/config/routing.py_tmpl

    r3211 r3247  
    1 """Setup your Routes options here""" 
     1"""Routes configuration 
    22 
    3 import os 
    4  
     3The more specific and detailed routes should be defined first so they may take 
     4precedent over the more generic routes. For more information refer to the 
     5routes manual at http://routes.groovie.org/docs/ 
     6""" 
     7from pylons import config 
    58from routes import Mapper 
    69 
    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')) 
     10def make_map(): 
     11    map = Mapper(directory=config['pylons.paths']['controllers'], 
     12                 always_scan=config['debug']) 
    1213     
    1314    # This route connects your root controller 
    1415    map.connect('*url', controller='root', action='route') 
    1516     
    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 
    2019    map.connect('error/:action/:id', controller='error') 
    2120     
    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 
    2522     
    26     map.connect('*url', controller='template', action='view', _encoding=None
     23    map.connect('*url', controller='template', action='view'
    2724     
    2825    return map 
  • trunk/tg/templates/turbogears/+package+/controllers/template.py_tmpl

    r3131 r3247  
    44    def view(self, url): 
    55        """ 
    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.:: 
    89         
    910            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  
    1817             
    1918            def view(self, url): 
    2019                try: 
    21                     return render_response('/'+url) 
    22                 except myghty.exception.ComponentNotFound
    23                     return Response(code=404) 
     20                    return render_response('/%s' % url) 
     21                except mako.exceptions.TopLevelLookupException
     22                    abort(404) 
    2423         
    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)  
    2725        """ 
    2826        abort(404) 
  • trunk/tg/templates/turbogears/+package+/lib/app_globals.py_tmpl

    r3131 r3247  
     1"""Pylons application's Globals object"""  
     2from pylons import config 
     3 
    14class 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. 
    2711        """ 
    2812        pass 
    29          
    30     def __del__(self): 
    31         """ 
    32         Put any cleanup code to be run when the application finally exits  
    33         here. 
    34         """ 
    35         pass 
  • trunk/tg/templates/turbogears/+package+/lib/base.py_tmpl

    r3131 r3247  
    1 from pylons import Response, c, g, cache, request, session 
     1from pylons import Response, c, g, cache, request, response, session 
    22from pylons.controllers import WSGIController 
    33from pylons.decorators import jsonify, validate 
  • trunk/tg/templates/turbogears/+package+/templates/index.html

    r3199 r3247  
    2424      <li><a href="http://groups.google.com/group/turbogears">Mail List</a> </li> 
    2525    </ul> 
    26     <span py:replace="now">now</span> 
     26    <span py:replace="now.strftime('%Y-%m-%d %H:%M')">now</span> 
    2727  </div> 
    2828  <div id="getting_started"> 
  • trunk/tg/templates/turbogears/+package+/websetup.py_tmpl

    r3131 r3247  
    1 import paste.deploy 
     1from paste.deploy import appconfig 
     2from pylons import config 
     3 
     4from ${package}.config.environment import load_environment  
    25 
    36def setup_config(command, filename, section, vars): 
     
    58    Place any commands to setup ${package} here. 
    69    """ 
    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) 
    1012