Iterating over a Python list with <dtml-in>
Dear newsgroup, I want to iterate over a list returned by a Python script using the <dtml-in> tag of Zope. The script looks like this: # Script BEGIN missing = [] for curprop in context.sqlGetObjectProperties(objid=curobjid): found = 0 for prop in context.sqlGetObjectTypeProperties(objtypid=curobjtypid): if (curprop.propid == prop.propid): found = 1 if (found == 0): missing.append(prop.propid) return missing # Script EOF The test DTML document looks like this <dtml-in expr="pyGetMissingObjectProperties(curobjid=objid,curobjtypid=objtypid)"> <dtml-var sequence-index><br> </dtml-in> and works fine, I see several sequence indexes. But how do I actually access the values from the list? <dtml-var missing> within the <dtml-in> block does not work :( Thanks for any help! Sven Jacobs
I want to iterate over a list returned by a Python script using the <dtml-in> tag of Zope. The script looks like this: [...]
Nevermind, found it out myself! There was an error in my Python script so <dtml-var sequence-item> was not working as expected! Sven Jacobs
On Friday 06 February 2004 09:37, Sven Jacobs wrote:
Dear newsgroup,
I want to iterate over a list returned by a Python script using the <dtml-in> tag of Zope. The script looks like this:
# Script BEGIN missing = []
for curprop in context.sqlGetObjectProperties(objid=curobjid):
found = 0
for prop in context.sqlGetObjectTypeProperties(objtypid=curobjtypid): if (curprop.propid == prop.propid): found = 1
if (found == 0): missing.append(prop.propid)
return missing # Script EOF
The test DTML document looks like this
<dtml-in expr="pyGetMissingObjectProperties(curobjid=objid,curobjtypid=objtypid)"> <dtml-var sequence-index><br> </dtml-in>
and works fine, I see several sequence indexes. But how do I actually access the values from the list? <dtml-var missing> within the <dtml-in> block does not work :(
Of course : "missing" is not a property of each item in the list : it's the list itself, which is returned by the Python script. To get the value of the item, just use <dtml-var sequence-item> (or <dtml-var toto> if each item in the list has a property called "toto"). Thierry
participants (2)
-
FLORAC Thierry -
Sven Jacobs