[Grok-dev] Re: subclassing grok.Container

Tres Seaver tseaver at palladion.com
Mon Nov 19 10:13:44 EST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christian Klinger wrote:
> Hi Grok Developers,
> 
> i try to make a Container Implementation for strom.zope [1].
> I take many ideas from the z3c.zalchemy package in
> zope.svn [2].
> 
> I think i have some problems by subclassing my StormContainer with
> grok.Container.
> 
> This is my implementation:
> 
> app.py
> ======
> from megrok.storm.stormcontainer import StormContainer
> 
> class PersonContainer(StormContainer, grok.Container):
>      def __init__(self):
>          super(PersonContainer, self).__init__()
>          self.setClassName('person.person.person.Person')
> 
> class Index(grok.View):
>      grok.name('index')
>      grok.context(PersonContainer)
> 
> 
> class CreatePerson(grok.AddForm):
>      grok.context(PersonContainer)
>      form_fields = grok.AutoFields(IPerson)
> 
>      @grok.action('Create')
>      def create(self, **kw):
> 
> 
> The Index work on the PersonContainer.
> 
> If i try to access <instance of PersonContainer>/createperson
> i got the error at the end of this mail.
> 
> If i change the order of my BaseClases for
> PersonConatiner in: PersonContainer(grok.Container, StromContainer)
> i get the createperson AddForm. But i don´t get the StormContainer
> Methods.
> 
> Any hints?

When mixing together classes which both have non-trivial '__init__'s,
you can't just rely on 'super' to call the base version:  it will pick
*one* of the two.  You likely need to invoke both versions explicitly, e.g.:

  def __init__(self):
      StormContainer.__init__(self)
      grok.Container.__init__(self)
      # other initialization here


Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHQago+gerLs4ltQ4RAgitAJ49WwQNFsDFeoP4p8W9TWBG2cmqvACgjehz
7A1iFNGHfw0B9SkrKa2yifU=
=oVCQ
-----END PGP SIGNATURE-----



More information about the Grok-dev mailing list