Skip to content

Commit

Permalink
[svn] * Updated default project template files for new configuration …
Browse files Browse the repository at this point in the history
…layout. Options

  to handle config now just in environment.py, and middleware.py handling just
  middleware.
* Removing mako tests, as its now the default. Default test changed from
  Myghty to Mako.
* Changing default templating to mako.

--HG--
branch : trunk
  • Loading branch information
bbangert committed Jul 3, 2007
1 parent 9e9df11 commit d7e4575
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 140 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,12 @@ Pylons Changelog
=================

0.9.6 (**svn**)
* Updated default project template files for new configuration layout. Options
to handle config now just in environment.py, and middleware.py handling just
middleware.
* Removing mako tests, as its now the default. Default test changed from
Myghty to Mako.
* Changing default templating to mako.
* Added the https decorator. It requires an action to be loaded via
https. Patch by ido. Fixes #241.
* Added upgrade instructions, and posted a copy on the wiki. Fixes #230.
Expand Down
13 changes: 8 additions & 5 deletions pylons/configuration.py
Expand Up @@ -208,7 +208,7 @@ def add_template_engine(self, engine, root, options=None, alias=None):
self['buffet.template_engines'].append(config)

def init_app(self, global_conf, app_conf, package=None,
template_engine=default_template_engine):
template_engine=default_template_engine, paths=None):
"""Initialize configuration for the application
``global_config``
Expand Down Expand Up @@ -240,14 +240,17 @@ def init_app(self, global_conf, app_conf, package=None,
conf.update(app_conf)
conf.update(dict(app_conf=app_conf, global_conf=global_conf))
conf.update(self.pop('environment_load', {}))


if paths:
conf['pylons.paths'] = paths

# XXX Legacy: More backwards compatibility locations for the package
# name
conf['pylons.package'] = conf['package'] = conf['app_conf']['package'] = package

self.push_process_config(conf)
self.set_defaults(template_engine)

def set_defaults(self, template_engine):
conf = self._current_obj()
# Ensure all the keys from defaults are present, load them if not
Expand Down Expand Up @@ -358,7 +361,7 @@ def set_defaults(self, template_engine):
self.add_template_engine(template_engine, conf['pylons.package'] + '.templates')

# Save our errorware values
conf['errorware'] = errorware
conf['pylons.errorware'] = errorware

config = PylonsConfig()

Expand Down
35 changes: 8 additions & 27 deletions pylons/database.py
Expand Up @@ -13,12 +13,9 @@
from paste.deploy.converters import asbool

import pylons
import pylons.util

__all__ = ["PackageHub", "AutoConnectHub"]

# Provide support for sqlalchemy
_db_engines = {}
try:
import sqlalchemy
from sqlalchemy.ext import sessioncontext
Expand All @@ -31,7 +28,7 @@ def app_scope():
application's Globals object at pylons.g (if one is registered).
"""
try:
app_scope_id = str(id(pylons.g._current_obj()))
app_scope_id = str(id(pylons.config._current_obj()))
except TypeError:
app_scope_id = ''
return '%s|%i' % (app_scope_id, thread.get_ident())
Expand All @@ -45,7 +42,7 @@ def create_engine(uri=None, echo=None, **kwargs):
uri, echo = get_engine_conf(uri, echo)
kwargs['echo'] = echo
engine_key = '%s|%s' % (uri, str(kwargs))
db_engines = get_engines()
db_engines = pylons.config['pylons.db_engines']
if engine_key in db_engines:
engine = db_engines[engine_key]
else:
Expand All @@ -58,31 +55,15 @@ def get_engine_conf(uri=None, echo=None):
echo) from the Pylons config file values ``sqlalchemy.dburi`` and
``sqlalchemy.echo`` when none are specified."""
if uri is None:
uri = pylons.util.config_get('sqlalchemy.dburi')
uri = pylons.config.get('sqlalchemy.dburi')
if not uri:
raise KeyError('No SQLAlchemy database config found!')
if echo is None:
echo = pylons.util.config_get('sqlalchemy.echo', False)
echo = pylons.config.get('sqlalchemy.echo', False)
if echo != 'debug':
echo = asbool(echo)
return uri, echo

def get_engines():
"""Return a dict of cached SQLAlchemy engines.
Engines are cached to an application's ``Globals`` (``g``) object. If
for whatever reason the ``g`` object has not been registered (outside
of a web request), engines are cached to the global ``engines`` dict
instead."""
try:
if not hasattr(pylons.g, '_db_engines'):
db_engines = pylons.g._db_engines = {}
else:
db_engines = pylons.g._db_engines
return db_engines
except TypeError:
return _db_engines


def make_session(uri=None, echo=None, session_kwargs=None, **kwargs):
"""Returns a SQLAlchemy session for the specified database uri from
the the engine cache (returned from ``get_engines``)``. Uses the
Expand Down Expand Up @@ -127,7 +108,7 @@ class AutoConnectHub(ConnectionHub):

def __init__(self, uri=None, pool_connections=True):
if not uri:
uri = pylons.util.config_get('sqlobject.dburi')
uri = pylons.config.get('sqlobject.dburi')
self.uri = uri
self.pool_connections = pool_connections
ConnectionHub.__init__(self)
Expand Down Expand Up @@ -240,13 +221,13 @@ def set_hub(self):
dburi = self.dburi
if not dburi:
try:
dburi = pylons.util.config_get("%s.dburi" % \
dburi = pylons.config.get("%s.dburi" % \
self.packagename)
except TypeError, e:
# No configuration is registered
raise UnconfiguredConnectionError(str(e))
if not dburi:
dburi = pylons.util.config_get("sqlobject.dburi")
dburi = pylons.config.get("sqlobject.dburi")
if not dburi:
raise UnconfiguredConnectionError(
"No database configuration found!")
Expand Down
@@ -1,29 +1,39 @@
import os

import pylons.config
from paste.deploy.config import CONFIG

from pylons import config
import webhelpers

from ${package}.config.routing import make_map

def load_environment(conf={}):

map = make_map(conf)
# Setup our paths
def load_environment(global_conf, app_conf):
# Create our paths
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = {'root_path': root_path,
'controllers': os.path.join(root_path, 'controllers'),
'templates': [os.path.join(root_path, path) for path in \
('components', 'templates')],
'static_files': os.path.join(root_path, 'public')
}

# Initialize the other basic options
config.init_app(global_conf, app_conf, package='${package}',
template_engine='${template_engine}', paths=paths)

map = make_map(config)
config['pylons.map'] = map

# The following template options are passed to your template engines
tmpl_options = {}
tmpl_options['myghty.log_errors'] = True
tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

# Add your own template options config options here, note that all config options will override
# any Pylons config options

# Return our loaded config object
return pylons.config.Config(tmpl_options, map, paths)
# The following template options are passed to your template engines
tmpl_options = {}

# Load-up the template options
config['buffet.template_options'] = tmpl_options

# Setup the Paste CONFIG object for legacy code
CONFIG.push_process_config(config._current_obj())

@@ -1,10 +1,11 @@
from paste.cascade import Cascade
from paste.urlparser import StaticURLParser
from paste.registry import RegistryManager
from paste.deploy.config import ConfigMiddleware, CONFIG
from paste.deploy.config import ConfigMiddleware
from paste.deploy.converters import asbool

from pylons.error import error_template
from pylons import config
from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
import pylons.wsgiapp

Expand All @@ -19,21 +20,14 @@ def make_app(global_conf, full_stack=True, **app_conf):
paste.deploy.converters should be used when parsing Paste config options
to ensure they're treated properly.
"""
# Setup the Paste CONFIG object, adding app_conf/global_conf for legacy code
conf = global_conf.copy()
conf.update(app_conf)
conf.update(dict(app_conf=app_conf, global_conf=global_conf))
CONFIG.push_process_config(conf)

# Load our Pylons configuration defaults
config = load_environment(conf)
config.init_app(global_conf, app_conf, package='${package}', template_engine='${template_engine}')
load_environment(global_conf, app_conf)

# Load our default Pylons WSGI app and make g available
app = pylons.wsgiapp.PylonsApp(config, helpers=${package}.lib.helpers,
app = pylons.wsgiapp.PylonsApp(helpers=${package}.lib.helpers,
g=app_globals.Globals)
g = app.globals
app = ConfigMiddleware(app, conf)

app = ConfigMiddleware(app, config._current_obj())

# YOUR MIDDLEWARE
# Put your own middleware here, so that any problems are caught by the error
Expand All @@ -44,7 +38,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
# catch the problems.
if asbool(full_stack):
# Error Handling
app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
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)
Expand All @@ -53,7 +47,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
# Establish the Registry for this application
app = RegistryManager(app)

static_app = StaticURLParser(config.paths['static_files'])
static_app = StaticURLParser(config['pylons.paths']['static_files'])
javascripts_app = StaticJavascripts()
app = Cascade([static_app, javascripts_app, app])
return app
5 changes: 1 addition & 4 deletions tests/test_webapps/filestotest/controller_sample.py
Expand Up @@ -30,14 +30,11 @@ def myparams(self):
def testdefault(self):
return render_response('testkid')

def testmako(self):
return render_response('/test_mako.html')

def test_extra_engine(self):
return render_response('kid', 'testkid')

def test_template_caching(self):
return render_response('/test_myghty.myt', cache_expire='never')
return render_response('/test_mako.html', cache_expire='never')

def test_only_post(self):
return Response('It was a post!')
Expand Down
@@ -1,6 +1,6 @@
from projectname.tests import *

class TestCheetahController(TestController):
class TestMakoController(TestController):
def test_mako(self):
response = self.app.get(url_for(controller='/sample', action='testmako'))
assert 'Hello, 5+5 is 10' in response
18 changes: 6 additions & 12 deletions tests/test_webapps/filestotest/middleware_cheetah_engine.py
Expand Up @@ -6,6 +6,7 @@
from paste.deploy.converters import asbool

from pylons.error import error_template
from pylons import config
from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
import pylons.wsgiapp

Expand All @@ -21,24 +22,17 @@ def make_app(global_conf, full_stack=True, **app_conf):
to ensure they're treated properly.
"""
conf = global_conf.copy()
conf.update(app_conf)
conf.update(dict(app_conf=app_conf, global_conf=global_conf))
CONFIG.push_process_config(conf)

# Load our Pylons configuration defaults
config = load_environment(conf)
config.init_app(global_conf, app_conf, package='projectname')
load_environment(global_conf, app_conf)

# Pull the other engine and put a new one up first
config.template_engines.pop()
config.add_template_engine('cheetah', 'projectname.cheetah', {})

# Load our default Pylons WSGI app and make g available
app = pylons.wsgiapp.PylonsApp(config, helpers=projectname.lib.helpers,
app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers,
g=app_globals.Globals)
g = app.globals
app = ConfigMiddleware(app, conf)
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
Expand All @@ -48,7 +42,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
app = httpexceptions.make_middleware(app, global_conf)

# Error Handling
app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
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)
Expand All @@ -57,7 +51,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
# Establish the Registry for this application
app = RegistryManager(app)

static_app = StaticURLParser(config.paths['static_files'])
static_app = StaticURLParser(config['pylons.paths']['static_files'])
javascripts_app = StaticJavascripts()
app = Cascade([static_app, javascripts_app, app])
return app
21 changes: 7 additions & 14 deletions tests/test_webapps/filestotest/middleware_def_engine.py
Expand Up @@ -6,6 +6,7 @@
from paste.deploy.converters import asbool

from pylons.error import error_template
from pylons import config
from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
import pylons.wsgiapp

Expand All @@ -21,25 +22,17 @@ def make_app(global_conf, full_stack=True, **app_conf):
to ensure they're treated properly.
"""
conf = global_conf.copy()
conf.update(app_conf)
conf.update(dict(app_conf=app_conf, global_conf=global_conf))
CONFIG.push_process_config(conf)

# Load our Pylons configuration defaults
config = load_environment(conf)
config.init_app(global_conf, app_conf, package='projectname')
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)
pylons.config.add_template_engine('kid', 'projectname.kidtemplates', kidopts)

# Load our default Pylons WSGI app and make g available
app = pylons.wsgiapp.PylonsApp(config, helpers=projectname.lib.helpers,
app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers,
g=app_globals.Globals)
g = app.globals
app = ConfigMiddleware(app, conf)
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
Expand All @@ -49,7 +42,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
app = httpexceptions.make_middleware(app, global_conf)

# Error Handling
app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
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)
Expand All @@ -58,7 +51,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
# Establish the Registry for this application
app = RegistryManager(app)

static_app = StaticURLParser(config.paths['static_files'])
static_app = StaticURLParser(config['pylons.paths']['static_files'])
javascripts_app = StaticJavascripts()
app = Cascade([static_app, javascripts_app, app])
return app

0 comments on commit d7e4575

Please sign in to comment.