Package advene :: Package model :: Module tales
[hide private]
[frames] | no frames]

Module tales

source code

TODO docstring

Special TALES attributes

Although TALES will search the attributes and item of an object when traversing it, it may be useful in some situations to provide TALES with specific attributes and methods.

Naming convention

When traversing object o with path element "a", TALES with first look for an attribute or method named "_tales_a". This allows classes to provide additional attributes, or even to override existing attributes in TALES.

Method decorators

This module provides a set of decorators (all functions named ``tales_X``) to be used with methods (either standard or TALES specific -- see `Naming convention`_) to customize the way TALES uses those methods.

Wrapping

In some cases, the naming convention and method decorators are not sufficient (i.e. when a mixin class should use the TALES specific version of an underlying method). For those cases, classes may provide the ``__wrap_with_tales_context__`` method. TALES will look for this method just before attempting to traverse an object, and if found, will replace that object by the result of the method.

Note that the wrapping will happen just before traversing: TALES will never return a wrapped object as the result of an expression.

TALES Global Methods

TALES global methods are functions that are available anywhere in a TALES path.

Warning

TALES global method should be avoided as much as possible, since they clutter the attribute space in interactive TALES editing, and may induce unexpected behaviours. However, there are some uses to them.

Classes [hide private]
  AdveneContext
  WithAbsoluteUrlMixin
This class provides a common implementation for the ``absolute_url`` tales function.
  _AbsoluteUrl
Used by `WithAbsoluteUrlMixin`.
Functions [hide private]
 
tales_full_path_function(f)
Decorator for TALES full-path-functions.
source code
 
tales_path1_function(f)
Decorator for TALES path1-functions.
source code
 
tales_context_function(f)
Decorator for TALES context-functions.
source code
 
tales_property(f)
Decorator for TALES property.
source code
 
tales_use_as_context(var)
Decorator with 1 argument to be used with TALES properties and context-functions (or it will have no effect).
source code
 
get_global_method(name)
Retrieves a global method, or return None if no such global method has been registered.
source code
 
iter_global_methods()
Iter over all the global method names.
source code
 
register_global_method(f, name=None)
Register f as a global method, under the given name, or under its own name if no name is provided.
source code
 
unregister_global_method(f_or_name)
Unregister a global method.
source code
 
_gm_repr(obj, context) source code
Variables [hide private]
  _global_methods = {}
Function Details [hide private]

tales_full_path_function(f)

source code 

Decorator for TALES full-path-functions.

A full-path-function will be immediately invoked, with the rest of the path as its sole argument.

tales_path1_function(f)

source code 

Decorator for TALES path1-functions.

A path1-function will be called with the next path element as its argument, rather than searching for an attribute or key with that name.

See advene.model.core.meta for an example.

tales_context_function(f)

source code 

Decorator for TALES context-functions.

When the last item of a path, and no-call is not used, a context-function is invoked with the context as its argument (rather than without any argument for other functions).

:see-also: `tales_use_context`

tales_property(f)

source code 

Decorator for TALES property.

A TALES property is similar in use to python's properties: it will automatically be called (with the context as its sole parameter) *even* if it has a subpath or if ``no-call:`` is used.

:see-also: `tales_use_context`

tales_use_as_context(var)

source code 

Decorator with 1 argument to be used with TALES properties and context-functions (or it will have no effect).

If the function expects a specific context variable rather than the context itself, the name of the variable can be specified with this decorator.

Example:

   @tales_property
   @tales_use_as_context("package")
   def some_method(self, a_package):
       ...

register_global_method(f, name=None)

source code 

Register f as a global method, under the given name, or under its own name if no name is provided.

f must accept two arguments: the object retrieved from the previous TALES path, and the TALES context.

unregister_global_method(f_or_name)

source code 

Unregister a global method. The parameter is the name of the global method, or can be the function if it has been registered under its own name.