Package turbogears :: Package view :: Module base

Module base

source code

Template processing for TurboGears view templates.

Classes
  MetaDeprecatedVariableProviders
  DeprecatedVariableProviders
  cycle
Loops forever over an iterator.
  UserAgent
Representation of the user's browser.
  DeprecatedBunch
Wraps access with a deprecation warning.
Functions
 
render(info, template=None, format=None, headers=None, mapping=None, fragment=False)
Renders data in the desired format.
source code
 
transform(info, template)
Create ElementTree representation of the output.
source code
 
loadBaseTemplates()
Load base templates for use by other templates.
source code
 
selector(expression)
If the expression is true, return the string 'selected'.
source code
 
checker(expression)
If the expression is true, return the string "checked".
source code
 
ipeek(it)
Lets you look at the first item in an iterator.
source code
 
stdvars()
Create a Bunch of variables that should be available in all templates.
source code
 
load_engines()
Load and initialize all templating engines.
source code
Variables
  log = logging.getLogger("turbogears.view")
  baseTemplates = []
  variable_providers = []
  root_variable_providers = []
  engines = {}
  variableProviders = []
Function Details

render(info, template=None, format=None, headers=None, mapping=None, fragment=False)

source code 

Renders data in the desired format.

Parameters:
  • info (dict) - the data itself
  • format (string) - "html", "xml" or "json"
  • headers (dict) - for response headers, primarily the content type
  • fragment (bool) - passed through to tell the template if only a fragment of a page is desired
  • template (string) - name of the template to use

loadBaseTemplates()

source code 

Load base templates for use by other templates.

By listing templates in turbogears.view.baseTemplates, these templates will automatically be loaded so that the "import" statement in a template will work.

selector(expression)

source code 

If the expression is true, return the string 'selected'.

Useful for HTML <option>s.

checker(expression)

source code 

If the expression is true, return the string "checked".

This is useful for checkbox inputs.

ipeek(it)

source code 

Lets you look at the first item in an iterator.

This is a good way to verify that the iterator actually contains something. This is useful for cases where you will choose not to display a list or table if there is no data present.

stdvars()

source code 
Create a Bunch of variables that should be available in all templates.

These variables are:

useragent
    a UserAgent object with information about the browser
selector
    the selector function
checker
    the checker function
tg_js
    the path to the JavaScript libraries
ipeek
    the ipeek function
cycle
    cycle through a set of values
quote_plus
    the urllib quote_plus function
url
    the turbogears.url function for creating flexible URLs
identity
    the current visitor's identity information
session
    the current cherrypy.session if the session_filter.on it set
    in the app.cfg configuration file. If it is not set then session
    will be None.
locale
    the default locale
inputs
    input values from a form
errors
    validation errors
request
    the cherrypy request
config
    the cherrypy config get function

Additionally, you can add a callable to turbogears.view.variable_providers
that can add more variables to this list. The callable will be called with
the vars Bunch after these standard variables have been set up.

load_engines()

source code 

Load and initialize all templating engines.

This is called during startup after the configuration has been loaded. You can call this earlier if you need the engines before startup; the engines will then be reloaded with the custom configuration later.