ZClass question - array of arrays
Hi, I'm having a little bit of a problem working out what ZClass property I should be setting. I want to record an array that can either contain strings or more arrays. eg: It can be ['a', 'b', 'c'] or ['a', ['b', 'c'], 'd'] or [['a','b'], ['c','d'], ['e','f']] The problem is that I can't work out what property type I should be setting this to be. I tried tokens, but tokens won't allow arrays to be saved, and both lines and strings assume that there will be a string (obviously), which means that I have to do a lot of splitting on [ and , before I can work with the data. The whole idea of the property is that if there is a scalar in position X, it shows the scalar, otherwise with an array, it shows a random value from that array. Is there an obvious type that I am missing? Thanks Dianne
Hi Dianne, This type of data structure can't be directly entered using any of the existing property types. You'll need to either write your own kind of property sheet view (which isn't actually a property sheet, more like a custom data entry form that you later pick apart), or allow people to enter in a Python expression which you later (unsafely) use "eval" against or (more safely) use a TALES "safe" Expression type to evaluate. See http://www.zopelabs.com/cookbook/1029970670 for more information. Dianne Van Dulken wrote:
Hi,
I'm having a little bit of a problem working out what ZClass property I should be setting. I want to record an array that can either contain strings or more arrays.
eg:
It can be
['a', 'b', 'c']
or
['a', ['b', 'c'], 'd']
or
[['a','b'], ['c','d'], ['e','f']]
The problem is that I can't work out what property type I should be setting this to be. I tried tokens, but tokens won't allow arrays to be saved, and both lines and strings assume that there will be a string (obviously), which means that I have to do a lot of splitting on [ and , before I can work with the data. The whole idea of the property is that if there is a scalar in position X, it shows the scalar, otherwise with an array, it shows a random value from that array.
Is there an obvious type that I am missing?
Thanks
Dianne
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com "Killing hundreds of birds with thousands of stones"
Hi Dianne,
Hi,
I'm having a little bit of a problem working out what ZClass property I should be setting. I want to record an array that can either contain strings or more arrays.
eg:
It can be
['a', 'b', 'c']
or
['a', ['b', 'c'], 'd']
or
[['a','b'], ['c','d'], ['e','f']]
The problem is that I can't work out what property type I should be setting this to be. I tried tokens, but tokens won't allow arrays to be saved, and both lines and strings assume that there will be a string (obviously), which means that I have to do a lot of splitting on [ and , before I can work with the data. The whole idea of the property is that if there is a scalar in position X, it shows the scalar, otherwise with an array, it shows a random value from that array.
Is there an obvious type that I am missing?
No, this is currently not possible to store other datatypes in properties. You can however try to write your own "plugin" property but then you have to work out the code in several places. If you try it, you will get at least great insight on the internal structure of Zope and the heads of the developers and their timepressure ;)) If you dont like it so hard, just convert it to a string, like repr() does or more complicated: StringIO,pickle and base64encode/-decode and save it as a string property. This has the advantage of beeing able to store and retrive even thru a html-form. (The use in html-forms is the force behind the current implementation. But then I think we miss at least the propertytype for :record or :records which are mapped to dictionaries. ) HTH Tino Wildenhain
participants (3)
-
Chris McDonough -
Dianne Van Dulken -
Tino Wildenhain