[Grok-dev] Re: shortcut to methods
Philipp von Weitershausen
philipp at weitershausen.de
Mon Mar 19 13:39:40 EDT 2007
Martijn Faassen wrote:
> Tim wrote:
> > > The implementation is almost already there as the xmlrpc grokker
> > > uses this approach.
>> Our XMLRPC view class already does this. Maybe you can take a look at
>> that implementation to get something for json?
> Please do note that a few months ago I tried exactly this and got
> terribly lost in the zope publishing machinery, and gave up.
The trick is to register variations of this class where the view's
browserDefault() method each time points to a different method, or
implement a generic browserDefault() method in the base class that
inspects the last URL segment and maps that to a method.
> Note also that instead of 'MethodViews' I think you should go all the
> way, and have a grok.JSON view instead, analogous to grok.XMLRPC. This
> would take care of serialization of return values to JSON automatically,
> instead of you having to write simplejson.dumps(self.json) in every
> single method.
Note that this doesn't have to be part of core Grok. It could be a
separate package, e.g. megrok.json.
> If you have other use cases besides JSON for MethodViews, please share
> them with us.
I've been playing with KSS in Grok and have come up with a similar need.
While for regular browser views it makes sense to have each view be a
separate class, it feels verbose for Ajax / JSON.
http://worldcookery.com -- Professional Zope documentation and training
More information about the Grok-dev