[Grok-dev] extending grok classes (grok.JSON)
Uli Fouquet
uli at gnufix.de
Sun Mar 10 10:49:51 UTC 2013
Hi there,
On Sun, 10 Mar 2013 12:44:00 +0530 Joshua Immanuel wrote:
> How do I add behavior to existing grok classes, especially grok.JSON.
>
> I tried sub-classing like:
>
> class MyJSON(grok.JSON):
> def __call__(self):
> # do something
> return super(MyJSON, self).__call__()
Try `grok.baseclass()`:
class MyJSON(grok.JSON):
grok.baseclass()
def __call__(self):
# do something
return super(MyJSON, self).__call__()
This way you tell Grok that the respective class acts as a base for
'real' components that provide JSON stuff (and should not be grokked).
Derived classes, however, will still be grokked.
>
> class MyAPI(MyJSON):
> def service_a(self):
> return {'something' : 'blah'}
>
> martian is complaining about lack of configuration for MyJSON. What is
> the right way of doing this?
Using grok.baseclass(), I think.
Best regards,
--
Uli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://mail.zope.org/pipermail/grok-dev/attachments/20130310/cf7c99e6/attachment.sig>
More information about the Grok-dev
mailing list