[Zope] Re: a little complicated AccessRules

Evan Simpson evan@4-am.com
Fri, 02 May 2003 10:25:23 -0500


martin f krafft wrote:
>   http://server.com/people/krafft
>   http://server.com/people/krafft/
> 
> should both invoke a ZPT at http://server.com/people/dispatch,
> making the information '/krafft' available to the ZPT.
> 
>   http://server.com/people/krafft/anything
> 
> should serve ./anything out of /people/krafft.

I'm not sure if I'm interpreting you correctly, but you seem to want:

http://server.com/people/<something>

...to pass the string "<something>" as a parameter to a ZPT, while:

http://server.com/people/<something>/<somethingelse>

...is served normally?

If you do it exactly this way, it is going to cause you pain the moment 
you try to manage /people, since your '/people/manage_main' will get 
handed off to dispatch.

I recommend adding a way to distinguish these special requests, such as 
a prefix for the path element. In that case, you want a Script inside 
/people set as the Access Rule for that Folder:

req = container.REQUEST
trstack = req['TraversalRequestNameStack']
if len(trstack) == 1 and trstack[0][0] == '*':
     # There's only one path element left to traverse,
     # and it starts with a '*' prefix
     req.set('dispatch_arg', trstack.pop()[1:])
     trstack.append('dispatch')

Then, in your ZPT, use "request/dispatch_arg" to access the parameter.

Cheers,

Evan @ 4-am