On 6/29/09 8:26 PM, Iain Duncan wrote:
> I'm wondering what the conventional wisdom is for doing bfg apps to
> handle crud operations with urls like
>
> /pet ->  list pets
>
> /pet/1 ->  view pet model, id 1
> /pet/1/view
>
> /pet/1/edit ->  edit pet model, id 1
>
> Is this something that can be handled well with both traversal and url
> dispatch? Are there any examples of it?

Let's imagine a view "pets":

from webob import Response

def pets(context, request):
     return Response ('OK')

when a URL comes in that is for a paricular pet:

from webob import Response


def pets(context, request):
     if request.subpath:
        petnum = request.subpath[0]
        return Response('OK with petnum %s' % petnum)
     return Response ('OK')

when a URL comes in with a particular action for a pet:

from webob import Response
from repoze.bfg.chameleon_zpt import render_template_to_response

def pets(context, request):
     if len(request.subpath) == 1:
        petnum = request.subpath[0]
        return Response('OK with petnum %s' % petnum)
     elif request.subpath == 2:
        petnum, action = request.subpath
        return render_request_to_response('%s.html' % action,
                                          petnum = petnum)
     return Response ('OK')

That's at least one way to handle it.  Another way is to register a view for 
"edit.html" against a "Pet" model.
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to