The SimpleContext class is provided for applications which only make use of the Albatross template functionality. If you look at the implementation of the class you will note that it is constructed from a number of mixin classes. Each of these classes implements some of the functionality required for interpreting Albatross templates.
Diagrammatically the SimpleContext class looks like this:
By implementing the execution context semantics in a collection of mixin classes Albatross allows you to change semantics by substituting mixins which implement the same interface. This is very useful when using the Albatross application objects.
You will probably always use this mixin in your execution context.
You will probably always use this mixin in your execution context.
If you are using Albatross application functionality, you will almost certainly use this mixin in your application class, not the execution context.
Albatross provides an application session. Applications which do not a session can use this mixin to disable session functionality.
Collectively these classes provide all of the functionality which is required to execute Albatross templates. The following table contains a list of all methods defined in the context.
Method | Mixin |
---|---|
add_session_vars(*names) | StubSessionMixin |
clear_locals() | NamespaceMixin |
del_session_vars(*names) | StubSessionMixin |
discard_file_resources(filename) | ResourceMixin |
encode_session() | StubSessionMixin |
eval_expr(expr) | NamespaceMixin |
flush_content() | ExecuteMixin |
flush_html() | ExecuteMixin |
form_close() | StubRecorderMixin |
form_open() | StubRecorderMixin |
get_lookup(name) | ResourceMixin |
get_macro(name) | ResourceMixin |
get_macro_arg(name) | ExecuteMixin |
get_tagclass(name) | ResourceMixin |
get_value(name) | NamespaceMixin |
has_value(name) | NamespaceMixin |
has_values(*names) | NamespaceMixin |
input_add(itype, name, value, return_list) | StubRecorderMixin |
load_session() | StubSessionMixin |
load_template(name) | TemplateLoaderMixin |
load_template_once(name) | TemplateLoaderMixin |
make_alias(name) | NamespaceMixin |
merge_request() | StubRecorderMixin |
pop_content_trap() | ExecuteMixin |
pop_macro_args() | ExecuteMixin |
push_content_trap() | ExecuteMixin |
push_macro_args(args) | ExecuteMixin |
register_lookup(name, lookup) | ResourceMixin |
register_macro(name, macro) | ResourceMixin |
register_tagclasses(*tags) | ResourceMixin |
remove_session() | StubSessionMixin |
reset_content() | ExecuteMixin |
save_session() | StubSessionMixin |
send_content(data) | ExecuteMixin |
set_globals(dict) | NamespaceMixin |
set_save_session(flag) | StubSessionMixin |
set_value(name, value) | NamespaceMixin |
should_save_session() | StubSessionMixin |
write_content(data) | ExecuteMixin |
Looking inside the context module you will notice some mixin classes which provide alternatives for some of the context functionality. The CachingTemplateLoaderMixin class can be used to replace the TemplateLoaderMixin. Likewise the NameRecorderMixin class is a drop-in replacement for the StubRecorderMixin class. These alternatives are used by some of the prepackaged application objects.
Although all of the template file examples in the Templates User Guide used the SimpleContext class as the execution context, you are much more likely to use something derived from the AppContext class defined in the app module. Since Albatross creates a new execution context to process each browser request, it makes sense to manage tag classes, macros, and lookup tables somewhere other than in the execution context.