Class property in object creation form
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 I forgot to tell you that I use Zope-2.6.0 with Python-2.1.3, and that I didn't found any good example or documentation about this point anywhere... Thanks for any help, Thierry -- Linux every day, keeps Dr Watson away... http://gpc.sourceforge.net -- http://www.ulthar.net
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
Thierry Florac writes:
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. Whenever similar questions came up ;-) , I always adviced the following:
declare objects you want to be exposed in the product context as additional constructors in "registerClass" (i.e. as an elements of its "constructors" argument, but not the first one as it plays a special role). I never did it myself. Thus, it may fail. Dieter
On Thu, 2002-12-05 at 23:05, Dieter Maurer wrote:
Thierry Florac writes:
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. Whenever similar questions came up ;-) , I always adviced the following:
declare objects you want to be exposed in the product context as additional constructors in "registerClass" (i.e. as an elements of its "constructors" argument, but not the first one as it plays a special role).
I never did it myself. Thus, it may fail.
No, no, it works very well !! That was the good solution... Many thanks, Thierry
participants (2)
-
Dieter Maurer -
Thierry Florac