OpenQuizz
Une application de gestion des contenus pédagogiques
|
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) |
![]() | |
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 | |
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.
def __init__ | ( | self, | |
environment, | |||
parent, | |||
name, | |||
blocks | |||
) |
def __contains__ | ( | self, | |
name | |||
) |
def __getitem__ | ( | self, | |
key | |||
) |
Lookup a variable or raise `KeyError` if the variable is undefined.
def __repr__ | ( | self | ) |
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`.
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.
def get | ( | self, | |
key, | |||
default = None |
|||
) |
Returns an item from the template context, if it doesn't exist `default` is returned.
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.
def get_exported | ( | self | ) |
Get a new dict with the exported variables.
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.
def resolve_or_missing | ( | self, | |
key | |||
) |
Resolves a variable like :meth:`resolve` but returns the special `missing` value if it cannot be found.
def super | ( | self, | |
name, | |||
current | |||
) |
Render a parent block.
blocks |
environment |
eval_ctx |
exported_vars |
|
static |
|
static |
|
static |
|
static |
|
static |
name |
parent |
resolve_or_missing |
|
static |
vars |