Package tdi :: Module template :: Class Template
[frames] | no frames]

Class Template

source code

object --+
         |
        Template
Known Subclasses:

Template class
Instance Methods
 
__init__(self, tree, filename, mtime, factory, loader=None)
Initialization
source code
str
__str__(self)
String representation of the node tree
source code
 
template(self)
Return a clean template (without any wrapper)
source code
Template
reload(self, force=False)
Reload template(s) if possible and needed
source code
bool
update_available(self)
Check for update
source code
 
render(self, model=None, stream=None, flush=False, startnode=None, adapter=None, prerender=None, preadapter=None)
Render the template into stream using model
source code
str
render_string(self, model=None, startnode=None, adapter=None, prerender=None, preadapter=None)
Render the template as string using model
source code
Template
overlay(self, other)
Overlay this template with another one
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Instance Variables
Factory factory
Template factory
str filename
The filename of the template
callable loader
Loader
any mtime
Last modification time key (None means n/a)
Properties
tdi.nodetree.Root tree
Prepared node tree
tdi.nodetree.Root virgin_tree
The node tree without overlay filters
str encoding
The template encoding
iterable source_overlay_names
Source overlay names
iterable target_overlay_names
Target overlay names

Inherited from object: __class__

Method Details

__init__(self, tree, filename, mtime, factory, loader=None)
(Constructor)

source code 
Initialization
Parameters:
  • tree (tdi.nodetree.Root) - The template tree
  • filename (str) - Filename of the template
  • mtime (int) - Last modification time of the template (maybe None)
  • factory (Factory) - Template factory
  • loader (callable) - Template loader
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 
String representation of the node tree
Returns: str
The string representation
Overrides: object.__str__

template(self)

source code 
Return a clean template (without any wrapper)

reload(self, force=False)

source code 
Reload template(s) if possible and needed
Parameters:
  • force (bool) - Force reload? (only if there's a loader present)
Returns: Template
The reloaded (new) template or self

update_available(self)

source code 
Check for update
Returns: bool
Update available?

render(self, model=None, stream=None, flush=False, startnode=None, adapter=None, prerender=None, preadapter=None)

source code 
Render the template into stream using model
Parameters:
  • model (any) - The model object
  • stream (file) - The stream to render to. If None, sys.stdout is taken.
  • flush (bool) - flush after each write? The stream needs a flush method in order to do this (If it doesn't have one, flush being True is silently ignored)
  • startnode (str) - Only render this node (and all its children). The node is addressed via a dotted string notation, like a.b.c (this would render the c node.) The notation does not describe a strict node chain, though. Between to parts of a node chain may be gaps in the tree. The algorithm looks out for the first matching node. It does no backtracking and so does not cover all branches (yet?), but that works fine for realistic cases :). A non-working example would be (searching for a.b.c):

    *
    +- a
    |  `- b - d
    `- a
       `- b - c
    
  • adapter (callable) - Usermodel adapter factory (takes the model). This adapter is responsible for method and attribute resolving in the actual user model. If omitted or None, the standard model_adapters.RenderAdapter is applied.
  • prerender (any) - Prerender-Model. If omitted or None, no prerendering will happen and the original template is rendered.
  • preadapter (ModelAdapterInterface) - Prerender-model adapter factory (takes the model and an attribute specification dict). If omitted or None, the standard model_adapters.RenderAdapter.for_prerender is applied.

render_string(self, model=None, startnode=None, adapter=None, prerender=None, preadapter=None)

source code 
Render the template as string using model
Parameters:
  • model (any) - The model object
  • startnode (str) - Only render this node (and all its children). See render for details.
  • adapter (callable) - Usermodel adapter factory (takes the model). This adapter is responsible for method and attribute resolving in the actual user model. If omitted or None, the standard model_adapters.RenderAdapter is applied.
  • prerender (any) - Prerender-Model
  • preadapter (ModelAdapterInterface) - Prerender-adapter
Returns: str
The rendered document

overlay(self, other)

source code 
Overlay this template with another one
Parameters:
  • other (Template) - The template layed over self
Returns: Template
The combined template

Instance Variable Details

factory

Template factory

filename

The filename of the template

loader

Loader

mtime

Last modification time key (None means n/a)

Property Details

tree

Prepared node tree
Get Method:
unreachable.fget(self)
Type:
tdi.nodetree.Root

virgin_tree

The node tree without overlay filters
Get Method:
unreachable.fget(self)
Type:
tdi.nodetree.Root

encoding

The template encoding
Get Method:
unreachable.fget(self)
Type:
str

source_overlay_names

Source overlay names
Get Method:
unreachable.fget(self)
Type:
iterable

target_overlay_names

Target overlay names
Get Method:
unreachable.fget(self)
Type:
iterable