On 3/19/06, Simon Belak <[EMAIL PROTECTED]
> wrote:
Nice, be sure to add it to recipes in the wiki (when Trac is back on-line).
Cheers,
Simon
Sean De La Torre wrote:
> I've written a decorator (attached) that automatically routes requests
> based on the http request-method type. I found this useful, and figured
> that there are others out there who will too.
>
> Here are a couple of example of how this works:
>
> Example 1: Default Behavior
> -----------------------------
> The example below works as follows:
> 1) The target method, edit, is decorated with the http_method_router
> decorator.
> 2) When edit is called, it will route all GET requests to edit_GET,
> and all POST requests to edit_POST
> 3) If an unmapped method is used (PUT or DELETE in this case), then
> edit_GET will be called by default. To change the default behavior,
> add the default parameter to the decorator:
> @http_method_router(default='some_other_method_name')
>
> Sample Code:
> --------------------------------------
> @turbogears.expose()
> @http_method_router()
> def edit(self, *args, **kwargs):
> pass
>
> def edit_GET(self, *args, **kwargs):
> pass
>
> def edit_POST(self, *args, **kwargs):
> pass
> ---------------------------------------
>
> Example 2: Alternate mappings
> -----------------------------
> The example below works as follows:
> 1) The alt_mappings parameter is specified with the mappings for
> the GET and POST requests.
> 2) All edit GET requests are routed to the show function, and
> all edit POST requests are routed to the update function.
> 3) In this case, since no other mappings are declared, and no
> default method was specified, all PUT and DELETE requests
> will cause a cherrypy.NotFound exception to be raised.
>
> Sample Code:
> --------------------------------------
> @turbogears.expose ()
> @http_method_router(alt_mappings=dict(GET='show', POST='update'))
> def edit(self, *args, **kwargs):
> pass
>
> def show(self, *args, **kwargs):
> pass
>
> def update(self, *args, **kwargs):
> pass
> ---------------------------------------
>
> Thanks,
>
> Sean
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

