def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='forum', template_engine='mako', paths=paths) config['routes.map'] = make_map() config['pylons.g'] = app_globals.Globals() config['pylons.h'] = forum.lib.helpers # Customize templating options via this variable tmpl_options = config['buffet.template_options'] #tmpl_options['mako.output_encoding'] = 'utf-8' #tmpl_options['genshi.output_encoding'] = 'utf-8' # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) config.add_template_engine('genshi', 'forum.templates', {}) #config['pylons.response_options']['charset'] = 'utf-8' #config['pylons.request_options']['charset'] = 'utf-8' reload(sys) sys.setdefaultencoding('utf-8')
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='fivecents', template_engine='jinja', paths=paths) config.add_template_engine('jinja', '', { 'jinja.package': 'fivecents', 'jinja.package_path': 'templates', 'jinja.use_memcache': False, 'jinja.cache_folder': 'data/templates', 'jinja.auto_reload': True, 'jinja.extension': 'jinja', }) config['routes.map'] = make_map() config['pylons.g'] = app_globals.Globals() config['pylons.h'] = fivecents.lib.helpers # Jinja's unable to request c's attributes without strict_c config['pylons.strict_c'] = True # Customize templating options via this variable tmpl_options = config['buffet.template_options']
def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment 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'} config.add_template_engine('kid', 'projectname.kidtemplates', kidopts) # The Pylons WSGI app app = PylonsApp() # 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) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) # 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) javascripts_app = StaticJavascripts() static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, javascripts_app, app]) return app
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='isitopen', template_engine='genshi', paths=paths) config['routes.map'] = make_map() config['pylons.g'] = app_globals.Globals() config['pylons.h'] = isitopen.lib.helpers # Customize templating options via this variable tmpl_options = config['buffet.template_options'] # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) engine = engine_from_config(config, 'sqlalchemy.') config['pylons.g'].sa_engine = engine # Translator (i18n) translator = Translator(ugettext) def template_loaded(template): template.filters.insert(0, translator) #translator.setup(template) # redo template setup to use genshi.search_path # This requires path notation in calls to render rather than dotted notation # e.g. render('index.html') not render('index') etc genshi = config['buffet.template_engines'].pop() # set None for template_root as not using dotted (python package) notation config.add_template_engine('genshi', None) tmpl_options = config['buffet.template_options'] tmpl_options['genshi.search_path'] = paths['templates'][0] tmpl_options["genshi.loader_callback"] = template_loaded
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 our Pylons configuration defaults load_environment(global_conf, app_conf) # Pull the other engine and put a new one up first config['buffet.template_engines'].pop() config.add_template_engine('cheetah', 'projectname.cheetah', {}) # 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 our Pylons configuration defaults load_environment(global_conf, app_conf) # Add the second engine kidopts = {'kid.assume_encoding':'utf-8', 'kid.encoding':'utf-8'} 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