Log in |
DTML Zclass ID Bug WorkaroundVersion 0.2 This short howto contains information collected on the [email protected] list. I used contributions from Ian C. Blenke, Toby Dickenson, Anthony Pfrunder and Jason Spisak. Feel free to get in touch about this document. Version history
The Zclass ID bugThis problem happens (in Zope 2.0.1) when you create a new product with a Zclass that subclasses the DTML Document or Method classes. In my case I also subclassed CatalogAware so that the new product instances could register themselves into the catalog. You then create an instance of this product and try to access its id property from a Python or DTML method. Example: This document is <dtml-var id>. It doesn't work. When viewing you get something like This document is <cstring>. or This document is <string>. Also, the id is empty when you try to edit it in a property sheet and it's not available from the catalog search results (though the object is correctly indexed if CatalogAware or indexed manually). If you don't subclass DTML Method or DTML Document the problem doesn't occur. Using the setName methodToby Dickenson suggest the following solution: add a setName call to the class constructor method. If your class is called myZClass for instance you will need to edit myZClass_add. Example: <!--#with "myZClass.createInObjectManager(REQUEST['id'], REQUEST)"--> <dtml-call "setName(REQUEST['id'])"> <!--#/with--> I used the setName line before any manage_editProperties or catalog lines. This worked for me. Creating a class instance in PythonJason Spisak also mentioned that you can use an external method to get class instances with id's. Example code (I didn't use it myself): from DateTime import DateTime from OFS import DTMLMethod def make_resume(self,rfile,id,title) ob=ob.__of__(self) if rfile: my_ob=self.Control_Panel.Products.MyClass() my_ob.id=id my_ob.propertysheets.MyProperties.manage_changeProperties( myproperty=rfile.read()) my_ob.manage_edit("""<!--#var standard_html_header--> <!--#var myproperty--><!--#var standard_html_footer-->""",title) my_ob=my_ob.__of__(ob) ob._setObject(id, my_ob) With this code you get an id just fine. |