tw.mods.base

class tw.mods.base.HostFramework(engines=None, default_view='toscawidgets', translator=<function <lambda> at 0xb74d9d14>, enable_runtime_checks=True, default_engine=None, aggregation_config=None)

This class is the interface between ToscaWidgets and the framework or web application that’s using them.

The an instance of this class should be passed as second argument to tw.core.middleware.ToscaWidgetsMiddleware which will call its start_request() method at the beginning of every request and end_request() when the request is over so I have a chance to register our per-request context.

A request-local proxy to a configured instance is placed at the beginning of the request at tw.framework

Constructor’s arguments:

engines
An instance of tw.core.view.EngineManager.
default_view
The name of the template engine used by default in the container app’s templates. It’s used to determine what conversion is neccesary when displaying root widgets on a template.
translator
Function used to translate strings.
enable_runtime_checks

Enables runtime checks for possible programming errors regarding modifying widget attributes once a widget has been initialized. Disabling this option can significantly reduce Widget initializatio time.

Note

This operation modifies the Widget class and will affect any application using ToscaWidgets in the same process.

aggregation_config

This option can either be None, or must be a dictionary. The dictionary can have two keys, js and css. The value of each key is a list of dicts with the following keys:

  • modname the module to create the resource link from.
  • filename the filename relative to the modname of the aggregated resources.
  • map the mapping-file for the aggregated resources. If not given, defaults to <filename>.map.
request_local

Track an object instance internally using a stack

The StackedObjectProxy proxies access to an object internally using a stacked thread-local. This makes it safe for complex WSGI environments where access to the object may be desired in multiple places without having to pass the actual object around.

New objects are added to the top of the stack with _push_object while objects can be removed with _pop_object.

start_request(environ)
Called by the middleware when a request has just begun so I have a chance to register the request context Widgets will use for various things.
end_request(environ)
Called by the middleware when a request has just finished so I can clean up.
url(url)
Returns the absolute path for the given url.
register_resources(resources)
Registers resources for injection in the current request.
pop_resources()
Returns returns the resources that have been registered for this request and removes them from request-local storage area.

Previous topic

tw.core.resources

Next topic

Contributors

This Page

Quick search