actions

Actions allow you to write code that looks like:

class RandomController(BaseController):
  def GET(self):
    return Redirect("/")

which I think looks a lot nicer than:

class RandomController(BaseController):
  def GET(self):
    self.head.status = "303 SEE OTHER"
    self.head.append("location", "/")

This module provides a few common Action classes to use, along with a BaseAction which can be inherited to create your own Actions.

class seshat.actions.BaseAction[source]

Provides a base for creating a new object which represents an HTTP Status code.

All returned data is checked if it is of type BaseAction and if so, the data/actions head is returned rather than the controllers head. This allows for a syntax like:

return NotFound()

which will cause the controller to return a 404 status code.

To create a new action, inherit this class then make a new __init__(self, *kargs) which sets self.head to a Head object.

class seshat.actions.Redirect(loc)[source]

Returns a 303 See Other status code along with a location header back to the client.

Parameters:loc (str) – The location to which the client should be redirect to
class seshat.actions.Unauthorized[source]

Returns a 401 Unauthorized status code back to the client

class seshat.actions.NotFound[source]

Returns a 404 Not Found code and the resulting 404 error controller to be returned to the client.