7.10.2 RandomPageModuleMixin

This class inherits from the PageModuleMixin class. It redefines the way in which page modules are selected.

Instead of the application calling the set_page() execution context method, the URL in the browser request controls which page module is loaded and processed for each request.

Page module management is inherited from PageModuleMixin. The base_dir argument to the constructor determines the root directory where modules are loaded from.

Page modules handled by this mixin have the following interface:

page_enter( ctx)
If this function is present in the page module it will be called every time the page module is used for a browser request.

The ctx argument contains the execution context.

page_process( ctx)
If this function is present in the page module it will be called when the application object executes the process_request() method. This occurs if the browser request was successfully validated.

Refer to page in section 4.1 for an overview of the application processing sequence.

page_display( ctx)
This is the only mandatory page module function. The application object calls this function when it executes the display_response() method as the final step before saving the browser session.

Refer to page in section 4.1 for an overview of the application processing sequence.

The RandomPageModuleMixin class has the following interface.

load_page( ctx)
This method implements part of the standard application processing sequence. It is called immediately after restoring the browser session. The ctx argument is the execution context for the current browser request.

The get_page_from_uri() method is called to determine the identifier of the page module that will be loaded. The identifier is then passed to the load_page_module() method (which is inherited from PageModuleMixin).

Refer to page in section 4.1 for an overview of the application processing sequence.

get_page_from_uri( ctx, uri)
The method uses the urlparse() function from the standard Python urlparse module to extract the path component from both the uri parameter and the value returned by the base_url() method (which returns the base_url argument to the application constructor).

The path component of the base_url is then used to split the path component of the uri. Element one (first split to the right of base_url) of the resulting string list is returned as the page identifier.

Override this method in your application if you wish to implement a your own scheme for mapping the request onto a page identifier.

load_badurl_template( ctx)
Called when your page template identified by the request URL does not exist. The ctx argument is the execution context for the current browser request.

Override this method if you want to supply a different error page template.

page_enter( ctx)
Called as soon as the page module has been loaded. The ctx argument is the execution context for the current browser request.

The page module page_enter() function is called by this method if a page module was located by the load_page() method.

process_request( ctx)
This method implements part of the standard application processing sequence. It is called if the browser request is successfully validated. The ctx argument is the execution context for the current browser request.

The page module page_process() function is called by this method if a page module was located by the load_page() method.

Refer to page in section 4.1 for an overview of the application processing sequence.

display_response( ctx)
This method implements part of the standard application processing sequence. It is called as the final stage just before the session is saved. The ctx argument is the execution context for the current browser request.

The page module page_display() function is called by this method if a page module was located by the load_page() method.

Refer to page in section 4.1 for an overview of the application processing sequence.