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

Public Member Functions

def __init__ (self, environment, parent, name, blocks)
 
def super (self, name, current)
 
def get (self, key, default=None)
 
def resolve (self, key)
 
def resolve_or_missing (self, key)
 
def get_exported (self)
 
def get_all (self)
 
def call (__self, __obj, *args, **kwargs)
 
def derived (self, locals=None)
 
def __contains__ (self, name)
 
def __getitem__ (self, key)
 
def __repr__ (self)
 
- Public Member Functions inherited from ContextMeta
def __new__ (mcs, name, bases, d)
 

Data Fields

 parent
 
 vars
 
 environment
 
 eval_ctx
 
 exported_vars
 
 name
 
 blocks
 
 resolve_or_missing
 

Static Public Attributes

 keys
 
 values
 
 items
 
 iterkeys
 
 itervalues
 
 iteritems
 

Detailed Description

The template context holds the variables of a template.  It stores the
values passed to the template and also the names the template exports.
Creating instances is neither supported nor useful as it's created
automatically at various stages of the template evaluation and should not
be created by hand.

The context is immutable.  Modifications on :attr:`parent` **must not**
happen and modifications on :attr:`vars` are allowed from generated
template code only.  Template filters and global functions marked as
:func:`contextfunction`\\s get the active context passed as first argument
and are allowed to access the context read-only.

The template context supports read only dict operations (`get`,
`keys`, `values`, `items`, `iterkeys`, `itervalues`, `iteritems`,
`__getitem__`, `__contains__`).  Additionally there is a :meth:`resolve`
method that doesn't fail with a `KeyError` but returns an
:class:`Undefined` object for missing variables.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  environment,
  parent,
  name,
  blocks 
)

Member Function Documentation

◆ __contains__()

def __contains__ (   self,
  name 
)

◆ __getitem__()

def __getitem__ (   self,
  key 
)
Lookup a variable or raise `KeyError` if the variable is
undefined.

◆ __repr__()

def __repr__ (   self)

◆ call()

def call (   __self,
  __obj,
args,
**  kwargs 
)
Call the callable with the arguments and keyword arguments
provided but inject the active context or environment as first
argument if the callable is a :func:`contextfunction` or
:func:`environmentfunction`.

◆ derived()

def derived (   self,
  locals = None 
)
Internal helper function to create a derived context.  This is
used in situations where the system needs a new context in the same
template that is independent.

◆ get()

def get (   self,
  key,
  default = None 
)
Returns an item from the template context, if it doesn't exist
`default` is returned.

◆ get_all()

def get_all (   self)
Return the complete context as dict including the exported
variables.  For optimizations reasons this might not return an
actual copy so be careful with using it.

◆ get_exported()

def get_exported (   self)
Get a new dict with the exported variables.

◆ resolve()

def resolve (   self,
  key 
)
Looks up a variable like `__getitem__` or `get` but returns an
:class:`Undefined` object with the name of the name looked up.

◆ resolve_or_missing()

def resolve_or_missing (   self,
  key 
)
Resolves a variable like :meth:`resolve` but returns the
special `missing` value if it cannot be found.

◆ super()

def super (   self,
  name,
  current 
)
Render a parent block.

Field Documentation

◆ blocks

blocks

◆ environment

environment

◆ eval_ctx

eval_ctx

◆ exported_vars

exported_vars

◆ items

items
static

◆ iteritems

iteritems
static

◆ iterkeys

iterkeys
static

◆ itervalues

itervalues
static

◆ keys

keys
static

◆ name

name

◆ parent

parent

◆ resolve_or_missing

resolve_or_missing

◆ values

values
static

◆ vars

vars

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