Beispiel #1
0
def tmpl_globals():
    """Create and return a dictionary of global variables for all templates.

    This function was adapted from :func:`pylons.templating.pylons_globals`
    to better suite our needs. In particular we inject our own gettext
    functions and get a performance boost from following the translator SOP
    once here instead of on every gettext call.

    """
    conf = config._current_obj()
    g = conf['pylons.app_globals']
    c = tmpl_context._current_obj()
    t = translator._current_obj()
    return {
        'config': conf,
        'c': c,
        'tmpl_context': c,
        'g': g,
        'app_globals': g,
        'h': conf['pylons.h'],
        'request': request._current_obj(),
        'response': response, # don't eval the SOP because this is rarely used
        'translator': t,
        'ngettext': t.ngettext,
        'ungettext': t.ungettext, # compat with standard pylons_globals()
        '_': t.gettext,
        'N_': N_,
        'XML': XML,
    }
Beispiel #2
0
def tmpl_globals():
    """Create and return a dictionary of global variables for all templates.

    This function was adapted from :func:`pylons.templating.pylons_globals`
    to better suite our needs. In particular we inject our own gettext
    functions and get a performance boost from following the translator SOP
    once here instead of on every gettext call.

    """
    conf = config._current_obj()
    g = conf['pylons.app_globals']
    c = tmpl_context._current_obj()
    t = translator._current_obj()
    req = request._current_obj()
    return {
        'config': conf,
        'c': c,
        'tmpl_context': c,
        'g': g,
        'app_globals': g,
        'h': conf['pylons.h'],
        'request': req,
        'settings': req.settings,
        'response': response, # don't eval the SOP because this is rarely used
        'translator': t,
        'ngettext': t.ngettext,
        'ungettext': t.ungettext, # compat with standard pylons_globals()
        '_': t.gettext,
        'N_': N_,
        'XML': XML,
    }
Beispiel #3
0
def tmpl_globals():
    """Create and return a dictionary of global variables for all templates.

    This function was adapted from :func:`pylons.templating.pylons_globals`
    to better suite our needs. In particular we inject our own gettext
    functions and get a performance boost from following the translator SOP
    once here instead of on every gettext call.

    """
    conf = config._current_obj()
    g = conf["pylons.app_globals"]
    c = tmpl_context._current_obj()
    t = translator._current_obj()
    req = request._current_obj()
    return {
        "config": conf,
        "c": c,
        "tmpl_context": c,
        "g": g,
        "app_globals": g,
        "h": conf["pylons.h"],
        "request": req,
        "settings": req.settings,
        "response": response,  # don't eval the SOP because this is rarely used
        "translator": t,
        "ngettext": t.ngettext,
        "ungettext": t.ungettext,  # compat with standard pylons_globals()
        "_": t.gettext,
        "N_": N_,
        "XML": XML,
    }
Beispiel #4
0
def make_app(global_conf, full_stack=True, **app_conf):
    """Create a WSGI application and return it
    
    global_conf is a dict representing the Paste configuration options, the
    paste.deploy.converters should be used when parsing Paste config options
    to ensure they're treated properly.
    
    """
    load_environment(global_conf, app_conf)

    # Pull the other engine and put a new one up first
    config.template_engines.pop()
    kidopts = {'kid.assume_encoding': 'utf-8', 'kid.encoding': 'utf-8'}
    pylons.config.add_template_engine('kid', 'projectname.kidtemplates',
                                      kidopts)

    # Load our default Pylons WSGI app and make g available
    app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers,
                                   g=app_globals.Globals)
    app = ConfigMiddleware(app, config._current_obj())

    # If errror handling and exception catching will be handled by middleware
    # for multiple apps, you will want to set full_stack = False in your config
    # file so that it can catch the problems.
    if asbool(full_stack):
        # Change HTTPExceptions to HTTP responses
        app = httpexceptions.make_middleware(app, global_conf)

        # Error Handling
        app = ErrorHandler(app,
                           global_conf,
                           error_template=error_template,
                           **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
        # intercepts 500)
        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)

    # Establish the Registry for this application
    app = RegistryManager(app)

    static_app = StaticURLParser(config['pylons.paths']['static_files'])
    javascripts_app = StaticJavascripts()
    app = Cascade([static_app, javascripts_app, app])
    return app
def make_app(global_conf, full_stack=True, **app_conf):
    """Create a WSGI application and return it
    
    global_conf is a dict representing the Paste configuration options, the
    paste.deploy.converters should be used when parsing Paste config options
    to ensure they're treated properly.
    
    """
    load_environment(global_conf, app_conf)
    
    # Pull the other engine and put a new one up first
    config.template_engines.pop()
    kidopts = {'kid.assume_encoding':'utf-8', 'kid.encoding':'utf-8'}
    pylons.config.add_template_engine('kid', 'projectname.kidtemplates', kidopts)
        
    # Load our default Pylons WSGI app and make g available
    app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers,
                                   g=app_globals.Globals)
    app = ConfigMiddleware(app, config._current_obj())
    
    # If errror handling and exception catching will be handled by middleware
    # for multiple apps, you will want to set full_stack = False in your config
    # file so that it can catch the problems.
    if asbool(full_stack):
        # Change HTTPExceptions to HTTP responses
        app = httpexceptions.make_middleware(app, global_conf)
    
        # Error Handling
        app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware'])
    
        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
        # intercepts 500)
        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
    
    # Establish the Registry for this application
    app = RegistryManager(app)
    
    static_app = StaticURLParser(config['pylons.paths']['static_files'])
    javascripts_app = StaticJavascripts()
    app = Cascade([static_app, javascripts_app, app])
    return app