[Zope-CMF] index_html acquisition

Chris Withers chrisw@nipltd.com
Fri, 16 May 2003 11:48:25 +0100

David Hart wrote:
> Chris Withers wrote:
>> Troy Farrell wrote:
>>> I suppose instead you could add this line to your __init__():
>>> setattr(self,'index_html',Acquision.Acquired)
>> You could write that slightly more neatly as:
>> self.index_html = Acquisition.Acquired
>> But why wouldn't you want to do it in the class declaration? 
> The class I've witten is used as a mix-in in a subclass of PloneSite. 
> The PloneSite generator creates an index_html object in the plone_root, 
> and hence setting self.index_html = Acquisition.Acquired throws an 
> error. At least I *think* that's what's going on. :)

The class declaration gets executed when the module containing it is imported, 
that's way before any PloneSite generator script is going to get called...

Your current code runs when the __init__ method of your class is run. __init__ 
runs when an instance of the class is created.

If your subclass that uses your mix-in class doesn't have a __init__, you'll be 
in trouble. If it does, the order in which PloneSite's __init__ and your 
mix-class'es __init__ get executed depend on how you call them in your 
subclass'es __init__.

Now, I don't know when PloneSite' generator (whatever that is...) gets executed. 
If it's after your class's __init__, then it might well set an index_html that 
will replace the one you've set up. If it's after, then your index_html will be 
there. Neither of the setting processes willresult in an error, the error will 
be happening because something is expecting index_html to be something that it