[Zope] Class property in object creation form

Thierry Florac thierry.florac@onf.fr
05 Dec 2002 18:14:17 +0100


On Thu, 2002-12-05 at 17:19, Thierry Florac wrote:
> 
>   Hi,
> 
> I'm currently building several Zope products working quite well but with
> which I have a problem : how can I define class properties (most often
> defined as lists actually) and use them in my creation forms written in
> DTML.
> 
> For example, I've tried to use:
> 
> in file MyProduct.py :
> 
>  class MyProduct(...):
>    MyProductProperty = [ 'item1', 'item2', 'item3' ]
> 
>    def getMyProductProperty(self):
>      return MyProduct.MyProductProperty
> 
> 
> in file __init__.py :
> 
>  import MyProduct
>  ...
>  def initialize(context):
>    context.registerClass (MyProduct.MyProduct,...)
>    ...
>  methods={'myproduct_property':MyProduct.MyProduct.getMyProductProperty}
> 
> 
> and finally in my DTML file :
> 
>   <dtml-in myproduct_property>
>   ...
>   </dtml-in>
> 
> 
> But when I call my creation script from the ZMI, I get an error:
> 
>   Traceback (innermost last):
> 
>     * Module ZPublisher.Publish, line 150, in publish_module
>     * Module ZPublisher.Publish, line 114, in publish
>     * Module Zope, line 171, in zpublisher_exception_hook
>     * Module ZPublisher.Publish, line 98, in publish
>     * Module ZPublisher.mapply, line 88, in mapply
>     * Module ZPublisher.Publish, line 39, in call_object
>     * Module Shared.DC.Scripts.Bindings, line 252, in __call__
>     * Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec
>     * Module App.special_dtml, line 174, in _exec
>     * Module DocumentTemplate.DT_In, line 628, in renderwob
>     * Module DocumentTemplate.DT_Util, line 201, in eval
>       __traceback_info__: myproduct_property
>     * Module <string>, line 0, in ?
>     * Module None, line 58, in getMyProductProperty
> 
>   ImportError: No module named MyProduct
> 

After a few additionnal tests, I 've tried another solution, with :

in MyProduct.py:

  MyProductProperties = [ 'item1', 'item2', 'item3' ]

  def getMyProductProperty(self):
    return MyProductProperties


and in __init__.py:

  methods={'myproduct_property': MyProduct.getMyProductProperty


Not everything works fine and without errors when and restart Zope.
But if I refresh my product, the list is empty in my DTML output.

Any idea of what's wrong ?? Is there anything to do for my product to be
refreshed correctly ??

Thanks,

  Thierry