Permalink
Browse files

Updated config to allow you to turn off more stuff without subclassin…

…g AppConfig.

Updated tests.base.TestConfig to call AppConfig's __init__ so that changes to config defaults don't break the tests unessisarily.

Updated AppConfig docstrings somewhat.

Updated README.txt to get rid of info that didn't belong.

--HG--
extra : convert_revision : svn%3A77541ad4-5f01-0410-9ede-a1b63cd9a898/trunk%405650
  • Loading branch information...
1 parent b45c418 commit 793f2050eedc0b37feb5025857f28502e7714b90 mramm committed Nov 3, 2008
Showing with 65 additions and 50 deletions.
  1. +1 −32 README.txt
  2. +62 −17 tg/configuration.py
  3. +2 −1 tg/tests/base.py
View
@@ -1,34 +1,3 @@
-TurboGears2
-===========
-
-Next generation Front-to-back web development megaframework built on Pylons.
-
-TurboGears2, provides a comprehensive web development toolkit.
-It is designed to help you create the basic outline of a database-driven
-web application in minutes.
-
-TurboGears provides you with sane default for designer friendly templates,
-tools to make AJAX, and dynamic Javascript driven pages easy on both the
-browser side and the server side.
-
-TurboGears is a project that is built upon a foundation of reuse and building up.
-In retrospect, much of the code that was home grown in the TurboGears project
-should have been released as independent projects that integrate with TurboGears.
-
TurboGears is licensed under an MIT-style license (see LICENSE.txt).
Other incorporated projects may be licensed under different licenses.
-All licenses allow for non-commercial and commercial use.
-
-Working on TG2
---------------
-
-To be able to build TG2 packages or install it for development, you
-need Paver::
-
- easy_install Paver
-
-You can then run::
-
- paver develop
-
-to start working with the development version of TG2.
+All licenses allow for non-commercial and commercial use.
View
@@ -1,4 +1,4 @@
-"""Simple AppSetup helper class"""
+"""Configuration Helpers for TurboGears 2"""
import os
import logging
from UserDict import DictMixin
@@ -35,10 +35,15 @@ class PylonsConfigWrapper(DictMixin):
proxy that allows for multiple pylons/tg2 applicatoins to live
in the same process simultaniously, but to always get the right
config data for the app that's requesting them.
+
+ Sites, with seeking to maximize needs may perfer to use the pylons
+ config stacked object proxy directly, using just dictionary style
+ access, particularly whenever config is checked on a per-request
+ basis.
"""
def __init__(self, dict_to_wrap):
- """Initialize by passing in a dictionary to be wrapped"""
+ """Initialize the object by passing in pylons config to be wrapped"""
self.__dict__['config_proxy'] = dict_to_wrap
def __getitem__(self, key):
@@ -81,7 +86,7 @@ class AppConfig(Bunch):
"""Class to store application configuration
This class should have configuration/setup information
- that is NECESSARY for proper application function.
+ that is *nessisary* for proper application function.
Deployment specific configuration information should go in
the config files (eg: dvelopment.ini or production.ini)
@@ -104,12 +109,14 @@ def __init__(self):
self.sa_auth.translations = Bunch()
#Set individual defaults
- self.stand_alone = True
- self.default_renderer = 'genshi'
+ self.auto_reload_templates = True
self.auth_backend = None
+ self.default_renderer = 'genshi'
self.serve_static = True
+ self.stand_alone = True
self.use_legacy_renderer = True
- self.auto_reload_templates = True
+ self.use_toscawidgets = True
+ self.use_transaction_manager = True
def setup_paths(self):
root = os.path.dirname(os.path.abspath(self.package.__file__))
@@ -127,10 +134,13 @@ def init_config(self, global_conf, app_conf):
"""Initialize the config object.
tg.config is a proxy for pylons.config that allows attribute style
- access, so it's automatically setup when we create the poylons config
+ access, so it's automatically setup when we create the pylons
+ config.
- Besides basic initialization, this method copies all the values
- in base_config into the ``tg.config`` object.
+ Besides basic initialization, this method copies all the values
+ in base_config into the ``pylons.config`` and ``tg.config``
+ objects.
+
"""
pylons_config.init_app(global_conf, app_conf,
package=self.package.__name__,
@@ -140,8 +150,11 @@ def init_config(self, global_conf, app_conf):
def setup_routes(self):
"""Setup the default TG2 routes
- Overide this and setup your own routes maps if you want to use routes.
+ Overide this and setup your own routes maps if you want to use
+ custom routes.
+
"""
+
map = Mapper(directory=config['pylons.paths']['controllers'],
always_scan=config['debug'])
@@ -153,10 +166,18 @@ def setup_routes(self):
config['routes.map'] = map
def setup_helpers_and_globals(self):
+ """Add Hepers and Globals objects to the config.
+
+ Overide this method to customize the way that ``app_globals``
+ and ``helpers`` are setup.
+ """
+
config['pylons.app_globals'] = self.package.lib.app_globals.Globals()
+ config['pylons.helpers'] = self.package.lib.helpers
config['pylons.h'] = self.package.lib.helpers
def setup_sa_auth_backend(self):
+ """This method adds sa_auth information to the config."""
defaults = {
'form_plugin': None
}
@@ -167,7 +188,17 @@ def setup_sa_auth_backend(self):
config['sa_auth'].update(self.sa_auth)
def setup_mako_renderer(self):
- """Setup a renderer and loader for mako templates"""
+ """Setup a renderer and loader for mako templates
+
+ Overide this to customize the way that the mako template
+ renderer is setup. In particular if you want to setup
+ a different set of search paths, different encodings, or
+ additonal imports, all you need to do is update the
+ ``TemplateLookup`` constructor.
+
+ You can also use your own render_mako function instead of the one
+ provided by tg.render.
+ """
from mako.lookup import TemplateLookup
from tg.render import render_mako
@@ -182,7 +213,10 @@ def setup_mako_renderer(self):
self.render_functions.mako = render_mako
def setup_genshi_renderer(self):
- """Setup a renderer and loader for Genshi templates"""
+ """Setup a renderer and loader for Genshi templates
+
+ Overide this to customize the way that the internationalization
+ filter, template loader """
from genshi.template import TemplateLoader
from tg.render import render_genshi
@@ -372,9 +406,16 @@ def setup_tg_wsgi_app(self, load_environment):
def make_base_app(global_conf, wrap_app=None, full_stack=True, **app_conf):
"""Create a tg WSGI application and return it
+ ``wrap_app``
+ a WSGI middleware component which takes the core turbogears
+ application and wraps it -- inside all the WSGI-components
+ provided by TG and Pylons. This allows you to work with the
+ full environ that your tg app would get before anything
+ happens in the app itself.
+
``global_conf``
- The inherited configuration for this application. Normally from
- the [DEFAULT] section of the Paste ini file.
+ The inherited configuration for this application. Normally
+ fromthe [DEFAULT] section of the Paste ini file.
``full_stack``
Whether or not this application provides a full WSGI stack (by
@@ -393,12 +434,16 @@ def make_base_app(global_conf, wrap_app=None, full_stack=True, **app_conf):
if wrap_app:
wrap_app(app)
app = self.add_core_middleware(app)
- app = self.add_tosca_middleware(app)
+
+ if self.use_toscawidgets:
+ app = self.add_tosca_middleware(app)
if self.auth_backend == "sqlalchemy":
app = self.add_auth_middleware(app)
-
- app = self.add_tm_middleware(app)
+
+ if self.use_transaction_manager:
+ app = self.add_tm_middleware(app)
+
if self.use_sqlalchemy:
if not hasattr(self, 'DBSession'):
# If the user hasn't specified a scoped_session, assume
View
@@ -116,7 +116,7 @@ def post_response(self, **kargs):
class TestConfig(AppConfig):
def __init__(self, folder, values=None):
-
+ AppConfig.__init__(self)
#First we setup some base values that we know will work
self.renderers = ['genshi']
self.render_functions = tg.util.Bunch()
@@ -128,6 +128,7 @@ def __init__(self, folder, values=None):
self.auto_reload_templates = False
self.use_legacy_renderer = True
self.serve_static = False
+
#Then we overide those values with what was passed in
for key, value in values.items():

0 comments on commit 793f205

Please sign in to comment.