Table Of Contents

Previous topic

Routes Config Settings

Next topic

SQLAlchemy and Transaction Config Settings

ToscaWidgets Config Settings

Status:Official

ToscaWidgets itself has a few different configuration settings. Here’s a few ways you can modify the way ToscaWidgets renders content.

TW Minification

TW 0.9.9+ support resource variants. This allows the developers to point TW at a different javascript/css/image library in the event you want to change the js files that are used. This is usually employed in minification of the javascript files. This is valuable when you want to run “debug” mode on your js files in development, but “minified” on production for speedups.

You can set this variable in two ways. Add the following line to your .ini file as:

#for "minified" files
toscawidgets.framework.resource_variant=min

#for "debug" files
toscawidgets.framework.resource_variant=debug

Note that this only works if your js wrapper has actually been set up to have multiple variants. If the library does not have variants, this variable will be ignored.

Toscawidgets Versions

TurboGears supports both the 0.9.x branches of ToscaWidgets and the 2.x TW code. ToscaWidgets is currently at a crossroads, with the 0.9.x branch being a very stable codebase, and TW2 providing speed benefits, easier use, and a simpler, easier to debug codebase. TW2 is currently in alpha, so it’s up to you to determine it’s level of stability before usage. TW and TW2 can be used simultaneously. To use them, modify the following config options:

base_config.use_toscawidgets – Set to False to turn off Toscawidgets. (default is True)

base_config.use_toscawidgets2 – Set to True to turn on Toscawidgets2. (default is False)

What this does is to allow ToscaWidgets to provide hooks for both entry and exit. On entry, ToscaWidgets handles server requests that are directed directly to the widget itself, bypassing the TG Controllers. On exit, TW middleware provides resource injection, which can actually insert links to resources like javascript files into your HTML code automatically. Both TW 0.9.x and TW 2.x support this usage. There is more information on [tw_middleware] and [tw2_middleware].

AppConfig Method Overrides

AppConfig.add_tosca_middleware(app)

Configure the ToscaWidgets middleware.

If you would like to override the way the TW middleware works, you might do something like:

from tg.configuration import AppConfig
from tw.api import make_middleware as tw_middleware

class MyAppConfig(AppConfig):

    def add_tosca2_middleware(self, app):

        app = tw_middleware(app, {
            'toscawidgets.framework.default_view': self.default_renderer,
            'toscawidgets.framework.translator': ugettext,
            'toscawidgets.middleware.inject_resources': False,
            })
        return app

base_config = MyAppConfig()

The above example would disable resource injection.

There is more information about the settings you can change in the ToscaWidgets middleware. <http://toscawidgets.org/documentation/ToscaWidgets/modules/middleware.html>

AppConfig.add_tosca2_middleware(app)

Configure the ToscaWidgets2 middleware.

If you would like to override the way the TW2 middleware works, you might do change your app_cfg.py to add something like:

from tg.configuration import AppConfig
from tw2.core.middleware import TwMiddleware

class MyAppConfig(AppConfig):

    def add_tosca2_middleware(self, app):

        app = TwMiddleware(app,
            default_engine=self.default_renderer,
            translator=ugettext,
            auto_reload_templates = False
            )

        return app
base_config = MyAppConfig()

The above example would always set the template auto reloading off. (This is normally an option that is set within your application’s ini file.)