controller

No app built with Seshat does much without controllers. This module provides a base controller class which can be used right away in its current state, or can be inherited from to create more advanced or custom controllers.

Basic use is like so:

from seshat.controller import Controller

class index(Controller):
  def GET(self):
    return "<h1>WAT</h1>"

By default all controllers have HEAD and GET methods. HEAD simply calls GET but strips the reponse body. (HEAD is probably broken for now but I’ll fix it eventually).

class seshat.controller.Controller(request=None, session=None)[source]

The parent of all controllers which Seshat will serve.

To use this to make a controller, override or add the request method (in all caps) which will be called for this controller. Eg:

from seshat.controller import Controller

class index(Controller):
  def GET(self):
    return "<h1>WAT</h1>"

then all GET based requests to this controller will return with the text <h1>WAT</h1> however all POST, PUT, DELETE calls will a 405 Method Not Supported error.

post_init_hook()[source]

Called at the end of __init__ this allows you to customize the creation process of your controller, without having to override __init__ itself.

This should accept nothing and return nothing.

pre_content_hook()[source]

Called before the request method is called and should return either None or Action object.

If there is a returned value other than None, this will skip calling the request method and simply return directly to dispatch, so make sure it returns an Action.

A good example of the use for this hook would be for authentication. You could for example, check a parameter set through a cookie and return something like a 401 Unauthorized if the param doesn’t represent a logged in user:

return actions.Unauthorized()
Return type:Action or None
post_content_hook(content)[source]

Gets called after the content generating request method has been called. This can be to further modify the content which is returned, or perform some other action after each request.

Parameters:content (str) – the content from the content generating request method that was called.
Returns:The original or modified content
Return type:str
HEAD()[source]

Will be called if the request method is HEAD

By default this will call GET() but return nothing, so that only the Headers are returned to the client.

GET()[source]

Will be called if the request method is GET