8.6 The Application Class

The Application class is the base class for all Albatross application objects.

The class inherits from the ResourceMixin class to allow all application resources to be loaded once and used for every browser request. The AppContext class directs all resource related execution context method here.

Figure: The Application class
 
\includegraphics[]{application}

The Application class introduces a number of new methods.

__init__(base_url)
When you inherit from the Application class you must call this constructor.

The base_url argument is used as the base for URLs produced by the <al-a> and <al-form> tags.

base_url()
Returns the base_url argument which was passed to the constructor.

run(req)
Implements the standard application run sequence as described on page in section 4.1. The browser request passed as the req argument is attached to the execution context as soon as the context has been created.

If an exception is caught then the handle_exception() method is called passing the req argument.

handle_exception(req)
This implements the default exception handling for applications. The req argument is the browser request which was passed to the run() method.

It creates a new execution context and formats a standard Python traceback in the locals.python_exc value, and a template interpreter traceback in the locals.html_exc value. It then tries to load the 'traceback.html' template file and execute it. This gives you the ability to control the presentation and reporting of exceptions.

If any exceptions are raised during the execution of 'traceback.html' the method writes both formatted exceptions as a <pre> formatted browser response.

template_traceback(tb)
Generates a template interpreter traceback from the Python stack trace in the tb argument.

load_session(ctx)
Calls the load_session() method of the execution context in the ctx argument.

save_session(ctx)
Calls the save_session() method of the execution context in the ctx argument.

remove_session(ctx)
Calls the remove_session() method of the execution context in the ctx argument.

validate_request(ctx)
Returns TRUE.

You should override this method in your application object if you need to validate browser requests before processing them.

pickle_sign(text)
Returns an empty string to prevent insecure pickles being sent to the browser. This is overridden in the PickleSignMixin class.

pickle_unsign(text)
Returns an empty string to prevent insecure pickles being accepted from the browser. This is overridden in the PickleSignMixin class.

merge_request(ctx)
Merges the fields from the browser request into the local namespace of the execution context passed in the ctx argument.

It calls the get_field_names() method of the execution context to retrieve the list of fields from the RecorderMixin class. Any fields named by get_field_names() which are not in the browser request will be set to None.

If no names are returned by get_field_names() then all fields from the browser request will be merged into the local namespace of the execution context.