Skipole WSGI generator.

Topics:

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

Development at GitHub:

github.com/bernie-skipole/skipole

Your project Python code

The projectfiles directory containing project myproj should have been created as previously described. Within it you will be developing ...projectfiles/myproj.py

myproj.py will already be set up to do most of the following work, but in summary, it needs to import the WSGIApplication class.

Creating an instance of this WSGISpplication object creates an 'application' which can be used by any WSGI web server.

An instance is created within myproj.py with the lines:


    from skipole import WSGIApplication
    application = WSGIApplication(project='myproj',
                                  projectfiles=PROJECTFILES,
                                  proj_data={},
                                  start_call=start_call,
                                  submit_data=submit_data,
                                  end_call=end_call,
                                  url="/")

Where 'PROJECTFILES' is the path to your projectfiles directory - this informs the object where the project JSON files can be found.

start_call, submit_data and end_call are three functions that you will provide. Minimum versions are available in myproj.py which you will develop further. They are called during the progress of a call:

start_call(called_ident, skicall)

start_call is called when the server initially receives an incoming call.

submit_data(skicall)

submit_data is called by Responder pages.

end_call(page_ident, page_type, skicall)

end_call is called after any Responders have handled the call and prior to returning the page.

These functions can in turn call on any further modules you wish to include within the package - hence you can access your own databases and functionality.

You will notice the framework passes the skicall object to your functions which contains a good deal of information you will need, more about it is given here:skicall

In particular your functions will create a PageData object, which is a dictionary-like object where widget field values can be set. These will be set in the page finally returned to the client. For further details:skicall.PageData

Before the application is ready, it needs to have the application from the 'skis' project added to it. Within myproj.py you will see this is done with:


    from skipole import skis
    skis_application = skis.makeapp()
    application.add_project(skis_application, url='/lib')

This 'skis' application serves javascript files used by the framework, so it is always needed.

add_project

This is a method of the WSGIApplication.

application.add_project(subapplication, url=None, check_cookies=None)

Your main application, generally served at '/' can have another 'sub' application added at a given path, so if you want to add a subapplication you would typically:

Place the sub project code location on your sys.path

Import the sub project to obtain its wsgi application

Call application.add_project with the sub project application and the url where it will be served.

The optional check_cookies argument can be set to a function which you would create, with signature:

def my_check_cookies_function(received_cookies, proj_data):

When a call is received, with a url that routes it to the sub application, if this function is defined, and set in the add_project method:

application.add_project(subapplication, url="/suburl", check_cookies=my_check_cookies_function)

Then initially, before the call is routed to the subapplication, your my_check_cookies_function is called, with the received_cookies dictionary, and with your application's proj_data dictionary. If your function returns None, the call proceeds unhindered to the subapplication. If however your function returns an ident tuple, of the form (projectname, pagenumber), then the call is routed to that page instead.

This is typically used to limit access to the subproject. For example your my_check_cookies_function could check for a valid received cookie, and if present, would return None, allowing access, but if not present, it would return the ident of a login page.

Besides an ident tuple, the function could just return a pagenumber, in which case the corresponding page of the root application would be called, or it could return a label, in which case the root application would check its label ident dictionary and find the target ident that way. The label should not point to a URL.

Exceptions

Your myproj.py module also imports four exceptions which you can use in your functions:

from skipole import FailPage, GoTo, ValidateError, ServerError

Further information about the exceptions and their arguments can be found at:

FailPage(message = '', section='', widget='', failpage=None)

GoTo(target, clear_submitted=False, clear_page_data=False)

ValidateError(message = '', section='', widget='', status='400 Bad Request')

ServerError(message = '', section='', widget='', status='500 Internal Server Error', code=0)

Further information is available within the skiadmin pages, and the Documentation link to the left.