OpenQuizz
Une application de gestion des contenus pédagogiques
ChoiceLoader Class Reference
Inheritance diagram for ChoiceLoader:
Collaboration diagram for ChoiceLoader:

Public Member Functions

def __init__ (self, loaders)
 
def get_source (self, environment, template)
 
def load (self, environment, name, globals=None)
 
def list_templates (self)
 

Data Fields

 loaders
 

Additional Inherited Members

- Static Public Attributes inherited from BaseLoader
 has_source_access
 

Detailed Description

This loader works like the `PrefixLoader` just that no prefix is
specified.  If a template could not be found by one loader the next one
is tried.

>>> loader = ChoiceLoader([
...     FileSystemLoader('/path/to/user/templates'),
...     FileSystemLoader('/path/to/system/templates')
... ])

This is useful if you want to allow users to override builtin templates
from a different location.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  loaders 
)

Member Function Documentation

◆ get_source()

def get_source (   self,
  environment,
  template 
)
Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate the template.

The source part of the returned tuple must be the source of the
template as unicode string or a ASCII bytestring.  The filename should
be the name of the file on the filesystem if it was loaded from there,
otherwise `None`.  The filename is used by python for the tracebacks
if no loader extension is used.

The last item in the tuple is the `uptodate` function.  If auto
reloading is enabled it's always called to check if the template
changed.  No arguments are passed so the function must store the
old state somewhere (for example in a closure).  If it returns `False`
the template will be reloaded.

Reimplemented from BaseLoader.

◆ list_templates()

def list_templates (   self)
Iterates over all templates.  If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.

Reimplemented from BaseLoader.

◆ load()

def load (   self,
  environment,
  name,
  globals = None 
)
Loads a template.  This method looks up the template in the cache
or loads one by calling :meth:`get_source`.  Subclasses should not
override this method as loaders working on collections of other
loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`)
will not call this method but `get_source` directly.

Reimplemented from BaseLoader.

Field Documentation

◆ loaders

loaders

The documentation for this class was generated from the following file: