JoshAshby/Fla.gr — pull request #7 by JoshAshby (2013-05-27 18:44:35+00:00)
Title: Router rework

What
--------
Adds an autoRoute() decorator to seshat.route which guesses the url based off the file hierarchy. Its usable with the regular route() decorator where you can specify the URL regex manually, which means that existing controllers do not need to be decorated with @autoRoute.
The benefit of the autoRoute() is that everything is easily machine generated, and the URL structure all matches across controllers, so the ability to later on make a function to return the link for a controller is much easier.
This also replaces all the manually entered controllerMap imports with a rather hacky function that tries to import every controller, recursively in the `controller` folder.
Finally there is a small update to baseHTTPObject of the addition of a self._404() which is just for easier redirects to 404 pages, along with moving things over to the autorouter, to make way for a template function to return a link to any page easily.
What Changes
----------------------
Because the autoRoute() uses the file hierarchy to generate the URL, it expects controllers that are decorated with it to be named in a certain way. It expects the name of the file which each controller resides in to contain `Controller` and for the class name of the controller class to match that of the folder hierarchy it is in. For example, if you have a folder design that looks like this: `./admin/dev/buckets/` and in that folder you have `bucketsIndexController.py` and `bucketsSaveController.py` then any controller class within `bucketsIndexController.py` must be named like so: `adminDevBucketsFunction` where `Function` is the name of the page. This will generate a URL like so: `/admin/dev/buckets/function`
If you want to add a new controller, then you no longer have to import it in controllerMap. Instead simply placing it in the controllers folder, and making sure that, if the controller is in a folder of its own (for organization or perhaps for the autoRouter) then the folder has the appropriate `__init__.py` ControllerMap will then automatically import the new controller the next time the app is (re)started.
Testing
----------
Basically everything needs tested, and when I merge this, I'll work on updating the unittests to make sure everything works as it should.