route

Along with needing to have controllers, an app also has to have routes to those controllers. This is accomplished through the route() decorator. This decorator will, if no arguments are supplied, use controller_folder and the file hierarchy of the controller to auto generate a route. Or you can optionally supply a custom url pattern. This pattern then gets converted to a dict when the url is matched. The structure of the url pattern is simple, variabled within the url are denoted by a colon. For example, in the pattern:

/user/:name/:email

the returned dict will be:

{"name": something,
 "email": something_else}
seshat.route.controller_folder = ''

The folder where the controllers are located in. Since the auto route generation uses folder hierarchy, this setting allows to you to have controllers in a single folder but not have that folder end up as the route prefix.

seshat.route.route(r=None, s=None)[source]

Class decorator that will take and generate a route table entry for the decorated Controller class, based off of its name and its file hierarchy if no route pattern is specified.

Use like so:

from seshat.controller import Controller
from seshat.route import route

@route()
class index(Controller):
    pass

which will result in a route for “/” being made for this controller.

controllers whose name is index automatically get routed to the root of their folders, so an index controller in “profiles/” will have a route that looks like “/profiles”

Controllers whose name is view will automatically get routed to any index route that has an attached ID. Eg:

# In folder: profiles/
class view(Controller):
  pass

will be routed to if the request URL is “/profiles/5” and the resulting id will be stored in Controller.request.url_params

class seshat.route.Route(controller=None, route=None, subdomain=None)[source]

Provides a base route table entry which is generated by the route() decorator described below.

controller = None

The controller object, of type Controller which this route represents

Type:Controller
class seshat.route_table.RouteTable[source]
add(container)[source]

Adds the given route container to the route table.

Parameters:r_container (Route) – The route container which contains the url and controller for a route.
get(request)[source]

Attempts to find the closest match to the given url, through comparing lots of regexs for a match against the url.

Parameters:request (urlparse.ParseResult) – The requested url
Returns:Controller or None