Skipole WSGI generator.

Topics:

Introduction Getting Started Your Code skiadmin start_call submit_data end_call Exceptions PageData SectionData skicall Serving wsgi Code Examples

Development at GitHub:

github.com/bernie-skipole/skipole

PageData

Your 'start_call', 'submit_data' and 'end_call' functions are used to populate the skicall object with widget field data which is set into the widget fields of the final template page returned.

To do this, create a PageData object.

from skipole import PageData

pd = PageData()

This instance is a dictionary-like object that also has certain attributes. It can be set with data, and then inserted into the skicall object with:

skicall.update(pd)

A copy of the current PageData object which has been set into skicall can be obtained using:

pd = skicall.get_pagedata()

The keys of the PageData instance pd, which you would set, are of the form:

pd[widgetname,fieldname] = value

This framework often refers to the key tuple (widgetname,fieldname) as a widgfield.

As well as dictionary keys, attributes can be set which override parameters set when the page is created:


The http status and headers are normally set automatically by the framework, but can also be set by:


pd.status - Sets the returned page status

pd.headers - Sets the returned page headers


If pd.headers is not set, then the following individual fields can be set if required.


pd.mimetype - Sets the header content-type field.

pd.enable_cache - If True sets header fields to instruct the client to cache the file, if False requests no caching.

pd.content_length - Sets the header field with the file size.


The following attributes set Template page parameters:


pd.add_jscript - Set to a string containing javascript code. This will be set within the pages automatically generated "$(document).ready(function(){})" and will be run when the page is loaded.

pd.backcol - Set the 'HTML' tag background color

pd.body_class - The CSS class of the 'BODY' tag

pd.ident_data - Set to a string, which will be returned as the 'skicall.ident_data' attribute if this page submits any data. The data is base64 encoded and added to hidden fields on each form and link widget.

pd.lang - Set the language, such as 'en' in the page 'HTML' tag. This is independent of the skicall lang and language attributes, though it would generally be set the same as skicall.language.

pd.last_scroll - Set True to display the page at its last scroll position

pd.localStorage - A dictionary of string keys and values to set in the browser storage

pd.sessionStorage - A dictionary of string keys and values to set in the browser storage

pd.set_cookie - Set with a http.cookies.BaseCookie object which will be appended to the page headers.

pd.show_backcol - Set True to enable the 'HTML' tag background color

pd.show_error - Error message to be shown on the page default error widget

pd.interval - A template page can request a JSON page at set intervals, this sets the interval time in seconds. Use 0 to disable the requests.

pd.IntervalTarget - The label or ident of the target requested, typically a Responder which sets the data into a JSON page which is then returned.

pd.CatchToHTML - a target label or ident which is called if a javascript error occurs when the page is updated by JSON call.


Attributes relevant to File pages:

pd.filepath - The path (relative to projectfiles) to the linked static file.


For SVG pages (dynamic created pages, not static files):

pd.height - Set the height

pd.width - Set the width


For CSS pages (dynamic created pages, not static files):

pd.cssimport - A string or a list

pd.colour_substitution - Set with a dictionary to substitute colours within the CSS file, see the ColourSubstitute Responder which uses this.


For JSON pages:

Those Widgets which submit data, or link to another page, are generally set with the page to call, and an HTML template page is returned. However some widgets can request a JSON page (requires javascript to be enabled in the client browser).

In this case an alternative HTML page such as 'no_javascript' can be set in the HTML link field, which will be shown if the JSON call fails due to javascript being disabled.

When a JSON request is made - you would typically call a Responder which sets the skicall data values into the target page 'general_json'. This being an empty JSON file which is then populated with the widget-field dictionary.

On being received by the client the page widget fields will be updated, this will be quick, as a whole page is not sent, and looks very dynamic. Only certain widgfields are 'JSON enabled' and can be updated - this is shown in the widget documentation for each field.

As well as widgets, on setting up a Template Page you will see that the page can be set to make a JSON call at set intervals. Again this can be useful to continuously update required fields on the page.

As well as widgfields, some specific PageData attributes can be set and returned in the JSON response, which have a particular effect, these are:

pd.ident_data - Set to a string, which will be returned as the 'skicall.ident_data' attribute with any submitted data.

pd.ClearAllErrors - If True, any widget displaying an Error will be cleared.

pd.localStorage - A dictionary of string keys and values to set in the browser storage

pd.sessionStorage - A dictionary of string keys and values to set in the browser storage

pd.interval - The interval time in seconds which the template page will request JSON updates. Use 0 to disable the requests.

pd.IntervalTarget - The label or ident of the target requested, typically a Responder which sets the data into a JSON page which is then returned.

pd.JSONtoHTML - A url, label or ident to divert to.

This causes the client to call this target url.

Similarly, the value 'CatchToHTML' can also be set.

pd.CatchToHTML - A label or ident.

This CatchToHTML target (typically a Responder leading to an HTML template) is called if the widgets being updated by a JSON call causes a javascript error of some sort, maybe due to an action not supported by the client browser. In this situation, the javascript error will be caught, and the CatchToHTML page will be called instead. This could be used in conjunction with:

pd.throw = "Any error message"

This causes a javascript exception to be thrown, and will cause the CatchToHTML page to be called, if one has been set. If CatchToHTML has not been set, then an alert box with the error message will be shown.

Methods

PageData.from_dict(pagedict)

This classmethod returns an instance of the PageData class given a dictionary as produced by the to_dict method.

pd.to_dict()

Returns a dictionary containing all the information of the PageData object, with keys as a string. This may be useful for storing the data in a cache or database.

pd.clear()

Clears all data from the instance.

pd.update(sectiondata)

Given a SectionData instance, updates the PageData object with the section data.

pd.get_section(sectionalias)

If this pd has been previously updated with a SectionData instance, then this method returns a SectionData object given the sectionalias. Returns None if the sectionalias is not recognised.

pd.delete_section(sectionalias)

If this pd has been previously updated with a SectionData instance, then this method deletes the section data given the sectionalias.

pd.get_value(sectionalias, widgetname, fieldname)

Returns the value, if previously given, of the widget field. If the widget required is not in a section, set the sectionalias argument to None. This function returns None if no value has been set.