[Grok-dev] shortcut to methods

Tim Terlegård tim at se.linux.org
Sun Mar 18 15:00:59 EDT 2007


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


More information about the Grok-dev mailing list