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

Module global_methods

source code

This module contains all the global methods to be automatically added to a new AdveneContext. Note that those method must import every module they need _inside_ their body in order to prevent cyclic references.

If called on an invalid target, the method should return None.

Functions [hide private]
 
absolute_url(target, context)
Return the absolute URL of the element.
source code
 
isa(target, context)
Check the type of an element.
source code
 
meta(target, context)
Access to meta attributes.
source code
 
view(target, context)
Apply a view on an element.
source code
 
snapshot_url(target, context)
Return the URL of the snapshot for the given annotation or fragment.
source code
 
player_url(target, context)
Return the URL to play the video from the element position.
source code
 
formatted(target, context)
Return a formatted timestamp as hh:mm:ss.mmmm
source code
 
first(target, context)
Return the first item of target.
source code
 
last(target, context)
Return the last item of target.
source code
 
rest(target, context)
Return all but the first items of target.
source code
 
query(target, context)
Apply a query on target.
source code
 
sorted(target, context)
Return a sorted list
source code
 
length(target, context)
Return the length of the target.
source code
 
randompick(target, context)
Return a random element from the target.
source code
 
old_related(target, context)
Return the related annotation.
source code
 
tag_color(target, context)
Return a color matching one of the tags.
source code
 
representation(target, context)
Return a concise representation for the element.
source code
 
color(target, context)
Return the color of the element.
source code
Function Details [hide private]

isa(target, context)

source code 

Check the type of an element.

Return an object such that target/isa/[viewable_class], target/isa/[viewable_type] and target/isa/[viewable_class]/[viewble_type] are true for the correct values of viewable_class and viewable_type. Note that for annotations and relations, viewable_type must be the QName for of the type URI.

Note that for contents, viewable_type can be a two part path, corresponding to the usual mime-type writing. The star ('*') character, however, is not supported. For example, if c1 has type 'text/*' and c2 has type 'text/plain', the following will evaluate to True: c1/isa/text, c2/isa/text, c1/isa/text/html; the following will of course evaluate to False: c2/isa/text/html.

meta(target, context)

source code 

Access to meta attributes.

Function to be used as a TALES global method, in order to give access to meta attributes.

This function assumes that the 'options' of the TALES context have a dictionnary named 'namespace_prefix', whose keys are prefices and whose values are corresponding namespace URIs.

The use of this function is (assuming that here is a Metaed object): here/meta/dc/version for example (where prefix 'dc' has been mapped to the Dublin Core namespace URI in 'namespace_prefix'.

snapshot_url(target, context)

source code 

Return the URL of the snapshot for the given annotation or fragment.

It can be applied to an annotation, a fragment or a millisecond position (integer).

player_url(target, context)

source code 

Return the URL to play the video from the element position.

The element can be an annotation, a fragment or a millisecond position (integer).

formatted(target, context)

source code 

Return a formatted timestamp as hh:mm:ss.mmmm

This method applies to either integers (in this case, it directly returns the formated string), or to fragments. It returns a dictionary with begin, end and duration keys.

first(target, context)

source code 

Return the first item of target.

Return the first element of =target=, which must obviously be a list-like object.

last(target, context)

source code 

Return the last item of target.

Return the last element of =target=, which must obviously be a list-like object.

rest(target, context)

source code 

Return all but the first items of target.

Return all elements of target but the first. =target= must obvioulsly be a list-like, sliceable object.

sorted(target, context)

source code 

Return a sorted list

This method applies either to list of annotations, that will be sorted according to their positions, or to any list of comparable items.

old_related(target, context)

source code 

Return the related annotation.

This is a shortcut for the case where there is only 1 binary relation.

We search first outgoingRelations. If none exist, we check incomingRelations.