[Grok-dev] shortcut to methods
Christian Theune
ct at gocept.com
Mon Mar 19 09:19:03 EDT 2007
Hi,
Our XMLRPC view class already does this. Maybe you can take a look at
that implementation to get something for json?
Christian
Am Sonntag, den 18.03.2007, 20:00 +0100 schrieb Tim Terlegård:
> What do you think about adding xmlrpc-ish method support for a more
> general case?
>
> Simplest is to take an example. Let's say we have a chat
> application and the client uses ajax/json to ask about new messages and
> to tell the server it wants to say something. The old way would be to
> implement a class for each json call.
>
> class NewMessages(grok.View):
> grok.context(Chat)
>
> def update(self):
> # do some stuff
> self.json = { ... }
>
> def render(self):
> simplejson.dumps(self.json)
>
> class Say(grok.View):
> grok.context(Chat)
>
> def update(self):
> ...
>
> def render(self):
> ...
>
> I would like to do it like this:
>
> class ChatView(grok.MethodViews):
> grok.context(Chat)
>
> def newmessages(self):
> # do some stuff
> return simplejson.dumps(self.json)
>
> def say(self, message):
> # do some stuff
> return simplejson.dumps(self.json)
>
> In the case of html the one method per view is just fine. But for json,
> xmlrpc, rest and perhaps other cases it's more convenient to have one
> class with several methods where each will be registered as a view.
>
> The implementation is almost already there as the xmlrpc grokker uses
> this approach.
>
> Tim
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
--
gocept gmbh & co. kg - forsterstraße 29 - 06112 halle/saale - germany
www.gocept.com - ct at gocept.com - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20070319/6867037d/attachment.bin
More information about the Grok-dev
mailing list