Catalog result brains not extendable
I'm trying to get some results from a catalog and add meta_data to it. It seems the only way I can do this using python scripts is by turning the each result object into a dictionary and then adding to that. This is due to the fact that you can't do a setattr on anything using a python script. Why not? Obviously for security reasons but surely there must be a less restrictive alternative than a blanket ban on using attributes on classes?
"Jay, Dylan" wrote:
I'm trying to get some results from a catalog and add meta_data to it.
What is this meta_data? What I'd do is add a meta_data column to the catalog with the name of your required data. Then add a script of the same name somewhere that it can be acquired by all the objects you want to index. This script should then calculate the value for the metadata as appropriate, using the 'context' object to get hold of the object being indexed. cheers, Chris
There's no ban for attributes other than __setattr__ and __setitem__. The Zope security machinery is built largely around these two methods plus __getattr__ and __getitem__. I would likely use an external method or perhaps Evan's XXXPythonScripts that don't have restrictions against doing __setattr__. - C "Jay, Dylan" wrote:
I'm trying to get some results from a catalog and add meta_data to it. It seems the only way I can do this using python scripts is by turning the each result object into a dictionary and then adding to that. This is due to the fact that you can't do a setattr on anything using a python script. Why not? Obviously for security reasons but surely there must be a less restrictive alternative than a blanket ban on using attributes on classes?
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
-- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com "Killing hundreds of birds with thousands of stones"
"Jay, Dylan" wrote:
I'm trying to get some results from a catalog and add meta_data to it.
In $ZOPE/lib/python/Shared/DC/ZRDB/Results.py find the "class r" definition, and add one line to it, like this: class r(Record, Implicit, brains, zbrains): _guarded_writes = 1 Now you can assign to attributes of result records. Cheers, Evan @ 4-am & Zope
But you know, now that I think of it, I don't even know that Record objects have a __dict__ to them, so thus I'm not sure if even an external method would work. The best idea here would be to use a "brain" object, although there's no documented way to do it. - c "Jay, Dylan" wrote:
I'm trying to get some results from a catalog and add meta_data to it. It seems the only way I can do this using python scripts is by turning the each result object into a dictionary and then adding to that. This is due to the fact that you can't do a setattr on anything using a python script. Why not? Obviously for security reasons but surely there must be a less restrictive alternative than a blanket ban on using attributes on classes?
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
-- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com "Killing hundreds of birds with thousands of stones"
participants (4)
-
Chris McDonough -
Chris Withers -
Evan Simpson -
Jay, Dylan