I'm storing a selection of a user to a database as string. This selection is a multiple selection from a select box and is outputted as a list. Now I want to iterate over this list (after retrieving it from the database), but how can I do this? How can I tell Zope that the string is actually a list? How can I typecast in Zope?
<dtml-call "list(something)">, but that won't work in this case as you'll get a resultant [something,]
Use a python or external method to make a list from your string. I am supposing you are storing a string representation of the list that looks like:
"['fred', 'bob', 'mary']"
Get rid of any punctuation you do not want with (e.g.)
theString = string.replace(theString, '[', ' ')
(Yes, there are more efficient ways to do this!)
Then, once you have a space-delimited list of items, you may use
theList = string.split(theString)
which will make a list of the words in the string. Return theList.
a python/external method is more elegant, but if you want this can be done in the same way from DTML: <dtml-call "REQUEST.set(theString, _.string.replace(theString, '[', ' '))"> <dtml-call "REQUEST.set(theList, _.string.split(theString))"> or using dtml-let But whether all this works depends much on what your database returns. Rik