Re: [Zope] get property of type 'list'
Hi, Andrei I think I have it figured out. I just submitted something similar to the Collector about an analogous problem I have been having with 'lines' properties. When you create your tokens property, you should make its value a string, like: '1 2 3' not a list: [1, 2, 3] If your data is in a list and you want to use that list as tokens, you need to join the list into a string first: mylist = ['1', '2', '3'] fortokens = string.join(mylist,' ') That's the python, but you can do it in DTML using _.string.join(. Be careful to convert your integers to strings first. What's happening to you is that the string representation of the list, "[1, 2, 3]" is getting stored verbatim as your tokens property, and ZPublisher/Converters.py is then splitting it on the spaces when you ask for it. Which is how you get that weird '[1,' '2,' '3]'. -- Jim Washington Andrei Belitski wrote: Hi! I add a list property to a DTML document of type 'tokens' (e.g. '[1, 2, 3]') wenn i try to retrieve it with _.getitem i get '[1,' '2,' '3]' instead of '1' '2' '3' How can I get Zope to interpret my property like a list not a string or whatever else? Thank you in advance! ___ Zope maillist - [EMAIL PROTECTED] 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 ) -- Jim Washington Center for Assessment, Evaluation and Educational Programming Department of Teaching and Learning, Virginia Tech ___ Zope maillist - [EMAIL PROTECTED] 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 )
[Zope] Potential BUG manage_addProperty(was: [Zope] get property of type 'list') (was: [Zope] get property of type 'list')
Hi Andrei Andrei Belitski writes: ... manage_addProperties(id='tok', type='tokens', value=[1,2,3,4]) ... ... dtml-tok; yields ['[1,', '2,', '3,', '4]'] ... I now understand what happens: You interpret "type='tokens'" in a way, that the property value is a list. And indeed, when you access such a property, you will get a list. However, "manage_addProperty" expects the value for a property with "type='tokens'" to be a *STRING*, more precisely, a string of whitespace separated tokens. It splits this string at whitespace to obtain the list (this will be a list of *STRING*, never integers). You do not meet this expectation. What "manage_addProperty" does is to convert your list into a string (this gives '[1, 2, 3, 4]') and then splits this string at whitespace. This might be considered a bug, as it is inconsistent with "PropertyManager._updateProperty" which only converts, if the value has type string. I am not sure, however. If "manage_addProperty" would behave in the same way as "_updateProperty", then you could store your list of integers. However, the first time that you change *ANY* property of this object (through the management interface), your property would be converted to "tokens" for presentation and converted into a list of *STRING*s during "manage_editProperties". Nevertheless, I do not see a reason for "manage_addProperty" and "_updateProperty" to behave differently. What you can do? Difficult to say! Currently, you can not safely use lists of integers as property values. They can very easily be converted into lists of strings. Can you live with lists of strings? Dieter ___ Zope maillist - [EMAIL PROTECTED] 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 )
[Zope] get property of type 'list'
Hi! I add a list property to a DTML document of type 'tokens' (e.g. '[1, 2, 3]') wenn i try to retrieve it with _.getitem i get '[1,' '2,' '3]' instead of '1' '2' '3' How can I get Zope to interpret my property like a list not a string or whatever else? Thank you in advance! ___ Zope maillist - [EMAIL PROTECTED] 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 )
RE: [Zope] get property of type 'list'
From: Andrei Belitski [mailto:[EMAIL PROTECTED]] I add a list property to a DTML document of type 'tokens' (e.g. '[1, 2, 3]') wenn i try to retrieve it with _.getitem i get '[1,' '2,' '3]' instead of '1' '2' '3' How can I get Zope to interpret my property like a list not a string or whatever else? Actually it IS treating it as a list: dtml-var "tokens[0]" Should return '1' This should list each item: dtml-in tokens dtml-var sequence-itembr /dtml-in Regards Max M ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] get property of type 'list'
Andrei Belitski writes: I add a list property to a DTML document of type 'tokens' (e.g. '[1, 2, 3]') wenn i try to retrieve it with _.getitem i get '[1,' '2,' '3]' instead of '1' '2' '3' Are you sure, it was '[1,' '2,' '3]' and not ['1', '2', '3', '4']? If it were, it would be really strange, unbelievable. ['1', '2', '3', '4'] would be normal, when you use a list (it definitely is one!) in e.g.: dtml-var "_.getitem('toks')" as a list (of cause) can not be part of a generated HTML page. It must be converted into a string. And the above it the string representation of a list. To get the representation, you seem to favour (though I do not understand why), you could use: dtml-var "_.str(_.getitem('toks'))[1:-1]" This make the string conversion explicitly ("_.str") and then keeps the slice "[1:-1]" which means everything beside the first and last character, i.e. you chop the '[]'. Dieter ___ Zope maillist - [EMAIL PROTECTED] 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 )