This class uses a separate Python module for each page in the application. This scales very well at runtime because at most two modules will be loaded for each request; one to process the browser request, and possibly another to display the response. Page modules are cached for further efficiency. The class is designed to be used where the application controls the sequence of pages seen in a browser session so the start page is also specified in the constructor.
Application page modules are loaded from a base directory which is specified by the constructor base_dir argument. The current application page is identified by the path to the page module relative to the module base directory. Page identifiers consist of an optional path component followed by a module name without extension. For example "login", "user/list", "home-page/default".
Page modules are loaded into a dummy __alpage__ namespace to avoid conflicts with python modules, so loading "user/list" actually imports the module as __alpage__.user.list.
To support pickling of instances defined in a page module, a dummy hierarchy of modules needs to be created. In the __alpage__.user.list case mentioned above, a temporary dummy module called __alpage__.user is registered. This will be replaced by the real user module later if it is loaded.
Note also that the SessionBase mixin uses an import hook while decoding the session to redirects attempts to load page modules (those that being with __alpage__) to the load_page_module() method.
Page modules handled by this mixin have the following interface:
ctx [, ...]) |
The ctx argument contains the execution context. Any extra arguments which are passed to the set_page() method are passed as optional extra arguments to this function.
ctx) |
The ctx argument contains the execution context.
ctx) |
Refer to page
ctx) |
Refer to page
The PageModuleMixin class has the following interface.
base_dir, start_page) |
The base_dir argument specifies the path of the root directory where page modules are loaded from. When deploying your application as a CGI program you can specify a relative path from the location of the application mainline. Apache sets the current directory to root so when using mod_python deployment you will need to specify a path relative to the root.
The start_page argument is a page identifier which specifies the first page that new browser session will see.
) |
) |
ctx) |
If no current page is defined in ctx then the method will invoke ctx.set_page() passing the page specified as the start_page argument to the application constructor.
The actual page module load is performed via the load_page_module() method.
Refer to page
ctx, name) |
ctx, args) |
The page module page_enter() function is called by this method.
ctx) |
The page module page_leave() function is called by this method.
ctx) |
The page module page_process() function is called by this method.
Refer to page
ctx) |
The page module page_display() function is called by this method.
Refer to page