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

Public Member Functions

def __init__ (self, package_name, package_path="templates", encoding="utf-8")
 
def get_source (self, environment, template)
 
def list_templates (self)
 
- Public Member Functions inherited from BaseLoader
def load (self, environment, name, globals=None)
 

Data Fields

 encoding
 
 manager
 
 filesystem_bound
 
 provider
 
 package_path
 

Additional Inherited Members

- Static Public Attributes inherited from BaseLoader
 has_source_access
 

Detailed Description

Load templates from python eggs or packages.  It is constructed with
the name of the python package and the path to the templates in that
package::

    loader = PackageLoader('mypackage', 'views')

If the package path is not given, ``'templates'`` is assumed.

Per default the template encoding is ``'utf-8'`` which can be changed
by setting the `encoding` parameter to something else.  Due to the nature
of eggs it's only possible to reload templates if the package was loaded
from the file system and not a zip file.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  package_name,
  package_path = "templates",
  encoding = "utf-8" 
)

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.

Field Documentation

◆ encoding

encoding

◆ filesystem_bound

filesystem_bound

◆ manager

manager

◆ package_path

package_path

◆ provider

provider

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