Package turbogears
[hide private]

Package turbogears

source code

TurboGears Front-to-Back Web Framework


Version: 1.0.4.4

Author: Kevin Dangoor

Copyright: Copyright 2005-2007 Kevin Dangoor and contributors

License: MIT

Submodules [hide private]

Functions [hide private]
 
error_handler(handler=None, rules=None) source code
 
exception_handler(handler=None, rules=None) source code
 
expose(template=None, validators=None, allow_json=None, html=None, format=None, content_type=None, inputform=None, fragment=False, as_format='default', mapping=None, accept_format=None)
Exposes a method to the web.
source code
 
flash(message)
Set a message to be displayed in the browser on next page display.
source code
 
redirect(redirect_path, redirect_params=None, **kw)
Redirect (via cherrypy.HTTPRedirect).
source code
 
start_server(root) source code
 
update_config(configfile=None, modulename=None)
Updates the system configuration either from a ConfigObj (INI-style) config file, a module name specified in dotted notation or both (the module name is assumed to have a ".cfg" extension).
source code
 
url(tgpath, tgparams=None, **kw)
Computes URLs.
source code
 
validate(form=None, validators=None, failsafe_schema=none, failsafe_values=None, state_factory=None)
Validate input.
source code
Variables [hide private]
  __warningregistry__ = {('Module turbogears was already importe...
  entrypoint = EntryPoint.parse('identity = turbogears.identity....
  extensions = pkg_resources.iter_entry_points("turbogears.exten...
  mochikit = MochiKitLink(name='js/MochiKit.js', charset=None, d...
Function Details [hide private]

expose(template=None, validators=None, allow_json=None, html=None, format=None, content_type=None, inputform=None, fragment=False, as_format='default', mapping=None, accept_format=None)

source code 
Exposes a method to the web.

By putting the expose decorator on a method, you tell TurboGears that
the method should be accessible via URL traversal. Additionally, expose
handles the output processing (turning a dictionary into finished
output) and is also responsible for ensuring that the request is
wrapped in a database transaction.

You can apply multiple expose decorators to a method, if
you'd like to support multiple output formats. The decorator that's
listed first in your code without as_format or accept_format is
the default that is chosen when no format is specifically asked for.
Any other expose calls that are missing as_format and accept_format
will have as_format implicitly set to the whatever comes before
the ":" in the template name (or the whole template name if there
is no ":". For example, <code>expose("json")</code>, if it's not
the default expose, will have as_format set to "json".

When as_format is set, passing the same value in the tg_format
parameter in a request will choose the options for that expose
decorator. Similarly, accept_format will watch for matching
Accept headers. You can also use both. expose("json", as_format="json",
accept_format="text/javascript") will choose JSON output for either
case: tg_format=json as a parameter or Accept: text/javascript as a
request header.

Passing allow_json=True to an expose decorator
is equivalent to adding the decorator just mentioned.

Each expose decorator has its own set of options, and each one
can choose a different template or even template engine (you can
use Kid for HTML output and Cheetah for plain text, for example).
See the other expose parameters below to learn about the options
you can pass to the template engine.

Take a look at the
<a href="tests/test_expose-source.html">test_expose.py</a> suite
for more examples.

@param template "templateengine:dotted.reference" reference along the
        Python path for the template and the template engine. For
        example, "kid:foo.bar" will have Kid render the bar template in
        the foo package.
@keyparam format format for the template engine to output (if the
        template engine can render different formats. Kid, for example,
        can render "html", "xml" or "xhtml")
@keyparam content_type sets the content-type http header
@keyparam allow_json allow the function to be exposed as json
@keyparam fragment for template engines (like Kid) that generate
        DOCTYPE declarations and the like, this is a signal to
        just generate the immediate template fragment. Use this
        if you're building up a page from multiple templates or
        going to put something onto a page with .innerHTML.
@keyparam mapping mapping with options that are sent to the template
        engine
@keyparam as_format designates which value of tg_format will choose
        this expose.
@keyparam accept_format which value of an Accept: header will
        choose this expose.
@keyparam html deprecated in favor of template
@keyparam validators deprecated. Maps argument names to validator
        applied to that arg
@keyparam inputform deprecated. A form object that generates the
        input to this method

redirect(redirect_path, redirect_params=None, **kw)

source code 

Redirect (via cherrypy.HTTPRedirect).

Raises the exception instead of returning it, this to allow users to both call it as a function or to raise it as an exception.

update_config(configfile=None, modulename=None)

source code 

Updates the system configuration either from a ConfigObj (INI-style) config file, a module name specified in dotted notation or both (the module name is assumed to have a ".cfg" extension). If both are specified, the module is called first, followed by the config file. This means that the config file's options override the options in the module file.

url(tgpath, tgparams=None, **kw)

source code 

Computes URLs.

tgpath can be a list or a string. If the path is absolute (starts with a "/"), the server.webpath and the approot of the application are prepended to the path. In order for the approot to be detected properly, the root object should extend controllers.RootController.

Query parameters for the URL can be passed in as a dictionary in the second argument *or* as keyword parameters.

Values which are a list or a tuple are used to create multiple key-value pairs.

validate(form=None, validators=None, failsafe_schema=none, failsafe_values=None, state_factory=None)

source code 

Validate input.

Parameters:
  • form (a form instance) - a form instance that must be passed throught the validation process... you must give a the same form instance as the one that will be used to post data on the controller you are putting the validate decorator on.
  • validators (dictionary or schema instance) - individual validators to use for parameters. If you use a schema for validation then the schema instance must be the sole argument. If you use simple validators, then you must pass a dictionary with each value name to validate as a key of the dictionary and the validator instance (eg: tg.validators.Int() for integer) as the value.
  • failsafe_schema (errorhandling.FailsafeSchema) - a schema for handling failsafe values. The default is 'none', but you can also use 'values', 'map_errors', or 'defaults' to map erroneous inputs to values, corresponding exceptions or method defaults.
  • failsafe_values (a dictionary or a single value) - replacements for erroneous inputs. You can either define replacements for every parameter, or a single replacement value for all parameters. This is only used when failsafe_schema is 'values'.
  • state_factory (callable or None) - If this is None, the initial state for validation is set to None, otherwise this must be a callable that returns the initial state to be used for validation.

Variables Details [hide private]

__warningregistry__

Value:
{('Module turbogears was already imported from /home/lucas/tmp/turboge\
ars/turbogears/__init__.pyc, but /var/lib/python-support/python2.4 is \
being added to sys.path',
  <class exceptions.UserWarning at 0x2b7253fe2e90>,
  3): 1}

entrypoint

Value:
EntryPoint.parse('identity = turbogears.identity.visitor')

extensions

Value:
pkg_resources.iter_entry_points("turbogears.extensions")

mochikit

Value:
MochiKitLink(name='js/MochiKit.js', charset=None, defer=False)