manage_changeProperties from Python, using ZClass instance located through ZCatalog
m_id is tokens type property inside "data" propertysheet in a ZClass. This Python Script works fine when called on the ZClass. It changes the value of m_id property. new_m_id=[777,888,999] context.propertysheets.data.manage_changeProperties(m_id=new_m_id) However, the following script does not change the value of m_id property. It runs as if everything is ok. It finds correct instance using "title", the x[0].m_id and x[0].title show correct values, but the "line x[0].manage_changeProperties(m_id=new_m_id)" has no effect whatsoever. x=context.Catalog_Org(title="aaa") print x[0].m_id print x[0].title new_m_id=[999,888,777] x[0].manage_changeProperties(m_id=new_m_id) print x[0].m_id I tried to call "x[0].propertysheets.data.manage_changeProperties(m_id=new_m_id)", but it fails with Error Type: AttributeError, Error Value: data -- Milos Prudek
However, the following script does not change the value of m_id property. It runs as if everything is ok. It finds correct instance
x=context.Catalog_Org(title="aaa") print x[0].m_id print x[0].title new_m_id=[999,888,777] x[0].manage_changeProperties(m_id=new_m_id) print x[0].m_id
OK, that was stupid of me. "x" is metadata, not an instance. I need to run the manage_changeProperties on the instance. But how can I construct this call? I know the title of the instance, and I can find the id of the instance... In Python Script: new_m_id=[999,888,777] stored_id=context.Catalog(title=stored_title)[0].id Now I need to call manage_changeProperies on that instance from that Python Script. Ideas: context.REQUEST.RESPONSE.redirect(my_id+"/change_m_id?+"new_m_id") I would have to write a dtml method "change_m_id" that call "manage_changeProperties" with parameter "new_m_id". But it would mean passing this parameter in the URL. Not very secure. Please note that "id" is an id of the ZClass instance, but m_id is a property (in propertysheets) of that instance, and its type is tokens (list). Any ideas, please? -- Milos Prudek
Milos Prudek writes:
However, the following script does not change the value of m_id property. It runs as if everything is ok. It finds correct instance
x=context.Catalog_Org(title="aaa") print x[0].m_id print x[0].title new_m_id=[999,888,777] x[0].manage_changeProperties(m_id=new_m_id) print x[0].m_id
OK, that was stupid of me. "x" is metadata, not an instance. I need to run the manage_changeProperties on the instance. But how can I construct this call? I know the title of the instance, and I can find the id of the instance... Yet another person that does not read my replies carefully :-(
As I told you, from Zope 2.3.3 on, the object returned from a catalog search has a method "getobject" (or some similar spelling) to get the object itself.... There is an article at "zope.org". I think, I wrote about it in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> and, indeed, I can look it up there. But, of course, it is your and not my problem..... Dieter
Milos Prudek writes:
... However, the following script does not change the value of m_id property. It runs as if everything is ok. It finds correct instance using "title", the x[0].m_id and x[0].title show correct values, but the "line x[0].manage_changeProperties(m_id=new_m_id)" has no effect whatsoever.
x=context.Catalog_Org(title="aaa") print x[0].m_id print x[0].title new_m_id=[999,888,777] x[0].manage_changeProperties(m_id=new_m_id) print x[0].m_id A catalog search does not return the true object but only the meta data remembered for the object at cataloging time.
You "manage_changeProperties" probably belongs to a the catalog (it's acquired). Because the catalog does not have a "m_id" property (I expect), nothing happens. When you work with Zope 2.3.3 or later, the catalog result has a method "getobject" (or something similar) which returns the true object and which you can use to change the properties. If you do not recatalog, the meta data in the catalog remain unchanged. Even if you recatalog, I am not sure whether x[0] magically changes its values. I expect not. Dieter
A catalog search does not return the true object but only the meta data remembered for the object at cataloging time.
Very true.
When you work with Zope 2.3.3 or later, the catalog result has a method "getobject" (or something similar)
Yes indeed. Based on your information, the following Python Script works great. It searches for a ZClass instance with title="aaa" and it changes the m_id property. rid=context.Catalog_Org(title="aaa")[0].data_record_id_ a=context.Catalog_Org.getobject(rid) print repr(a.propertysheets.data.m_id) a.propertysheets.data.manage_changeProperties(m_id=[111,222,333]) a.reindex_object() print repr(a.propertysheets.data.m_id) return printed
to change the properties. If you do not recatalog, the meta data in the catalog remain unchanged. Even if you recatalog, I am not sure whether x[0] magically changes its values. I expect not.
It does change, actually. The two lines "print repr(a.propertysheets.data.m_id)" prove it. Thank you very much, Dieter. The information you gave me is actually written in the Zope Book Appendix B, and it is my fault that I did not notice it. I'm going to study Appendix B more thoroughly. -- Milos Prudek
participants (3)
-
Dieter Maurer -
Milos Prudek -
Milos Prudek