[Grok-dev] Re: subclassing grok.Container
Christian Klinger
cklinger at novareto.de
Mon Nov 19 10:43:57 EST 2007
Tres Seaver schrieb:
> -----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
Hi Tres
thanks for your tip but this doesen´t slove the problem. :-((
I have the feeling that traversal does not work on my subclassed
Container....
Christian
More information about the Grok-dev
mailing list