[Zope-CMF] addProduct vs init. Need explanations

Pascal Samuzeau samuzeau@oreka.com
Wed, 06 Nov 2002 09:09:26 +0100


Hi Dieter,                                                            
                                                                      
>  > Ok, But What addProductA for ?                                   
                                                                      
> It is the function that creates your new "ProductA" objects and adds
> them to a container.                                                
> Usually, it is the action use in the form that requests the         
necessary                                                             
> parameters for object creation. This form in turn is usually        
> activated by the ZMI's "add list".                                  
                                                                      
Well, if I admit what you told me, I should wrote something like:     
                                                                      
def addProductA(self,id,title,and_some_others):                       
    # productA = ProductA(id=id,title=title,and_some_others_too)      
class ProductA():                                                     
    def __init__(self,id,title,and_some_others):                      
    # what I want here                                                
    ....                                                              
                                                                      
I you noticed, I have commented the line                              
  # productA = ProductA(id=id,title=title,and_some_others_too) in the 
def addProductA()                                                     
                                                                      
Now, If I restart Zope, and add the new product, I should have        
normally either a raise error, at least nothing will happen. But what 
it my surprise to discovery that the product is installed with the    
parameters passed throught the ZMI's html page !!!!                   
                                                                      
                                                                      
>  > I mean if I add a ProductA under a CMFSite, only the init'class  
is                                                                    
>  > calling.                                                         
                                                                      
                                                                      
That only what I was telling to you, only the init's class function is
called.                                                               
                                                                      
                                                                      
> Should I understand what you are saying here?                       
>                                                                     
                                                                      
                                                                      
> When you use your product as content class of a CMF Type, then      
> you would put the "addProductA" as "Product Factory" in the type    
> description.                                                        
>                                                                     
                                                                      
Oh, no, just I want to add a new object of the type of my product by  
calling addProduct only, just to keep out of the init's class function
what I want to be done outside of the real needing of this class.     
                                                                      
                                                                      
And to intend to do this, I think I have not yet understand the       
difference between init's class and addProduct' calling (which calls  
the init's class in fact...)                                          
                                                                      
Cheers                                                                
PS                                                                    
--------------------------------------------------                    
Oreka ! Nous sommes l'internet moins cher !                           
Surfez 25% moins cher avec http://www.oreka.com