[Zope3-Users] Re: views based on request method (GET, POST, etc.)

Philipp von Weitershausen philipp at weitershausen.de
Wed Sep 13 05:34:46 EDT 2006


Jan-Wijbrand Kolman wrote:
> Stephan Richter wrote:
>> On Tuesday 12 September 2006 07:38, Jan-Wijbrand Kolman wrote:
>>> But I have the feeling this can be done more elegantly. I did notice
>>> something in this direction in zope/app/dav/configure.zcml, but I'm not
>>> sure this actually helps. It could be I overlook something very very
>>> obvious...
>>
>> you have two choices:
>>
>> 1. Implement HTTP verbs as methods. See the resources implementation. 
>> zope.app.publisher.browser
>>
>> 2. Register some view having the method name as the view name. See 
>> SchoolTool's REST implementation, for example, schooltool.person.rest.
> 
> Hi Stephan!
> 
> 
> The first option would work just fine for me indeed.
> 
> Out of curiosity though, I wonder about the second option:
> 
> I *think* to understand that for this option to work, 
> z.a.publication.http.HTTPublication must be used for handling requests 
> (instead of z.a.publication.browser.BrowserRequest), right?

At least you'd want your publication to look up views like the 
HTTPPublication, yes.

You probably want to implement your own publication that works on 
browser requests but immitates the HTTPPublication behaviour (though 
probably only in some cases, I assume). Custom publication/request 
factories can be registered with the 'publisher' ZCML directive:

   <publisher
       name="HTTP"
       factory="mycorp.mypkg.MyHTTPFactory"
       methods="GET POST"
       mimetypes="*"
       priority="1000"
       />

Factories with higher priorities will be called first. They can decide 
whether they want to handle a request based on the (CGI) environment of 
the request. If they decide not to handle, the next factory takes over. 
The fallback is the browser factory, then the HTTP factory. See 
z.a.publication/configure.zcml.

HTH

Philipp



More information about the Zope3-users mailing list