On Tue, 14 Mar 2000, Daniel.Weber@SEMATECH.Org wrote:
I've put the following in a SQL method, but can't figure out where the count ends up...
<dtml-in "_.string.split(tool_id)">
tool_id is a string (like 'EXP01 EXP02 EXP03'). For my normal DB activities I use count-attribute name for the count total, but I can't seem to find out where the count is stored in this example... I tried getting the key with sequence-key, which returned 1, but count-1 returns 0.
if you want the size of the list, just use sequence-size
I can't get this to work at all: <dtml-if "sequence-size > 1"> zope complains about not being able to find 'sequence'. I had solved this issue before with a let tag <dtml-let size=sequence-size>, but it seems very wasteful and adds a lot of syntax overhead to the code. How can I access the sequence variable in an expression?
from this, it looks as though you want to check if you're at the start of the list, in which case you can test sequence-start Actually, I'm checking to see if I've got multiple elements. If I do, then I use IN () in my DB query, else I put in =. When I split the string, I don't know if I have multiple items.
----- Original Message ----- From: <Daniel.Weber@sematech.org> To: <zope@zope.org> Sent: Tuesday, March 14, 2000 8:48 AM Subject: RE: [Zope] dtml-in iteration over a string.split
I can't get this to work at all: <dtml-if "sequence-size > 1"> zope complains about not being able to find 'sequence'. I had solved this issue before with a let tag <dtml-let size=sequence-size>, but it seems very wasteful and adds a lot of syntax overhead to the code. How can I access the sequence variable in an expression?
Since python interprets "sequence-size" to be sequence minus size, you need to do a namespace lookup to get at the value. <dtml-if "_['sequence-size'] > 1"> will do the trick. Kevin
On Wed, 15 Mar 2000, Daniel.Weber@SEMATECH.Org wrote:
I can't get this to work at all: <dtml-if "sequence-size > 1"> zope complains about not being able to find 'sequence'. I had solved this issue before with a let tag <dtml-let size=sequence-size>, but it seems very wasteful and adds a lot of syntax overhead to the code. How can I access the sequence variable in an expression?
OK.. Two points. Firstly, my appology. I mistakenly believed sequence-size existed, since it's previous- and next- counterparts do. However, sequence-length aparently does. (there is a reference to it in the ZQR, and it's also in the source code.) Secondly, your problem stems from the fact that sequence-length is not a valid variable name in Python. you must use <dtml-if "_['sequence-size'] > 1"> Annoying, yes... but that's the way somebody chose to go. I don't know why, but it's there. In fact, if anyone could give me a good reason why it is this way, I would be most appreciative. -- Have a better one, Curtis. <dtml-var standard_work_disclaimer>
Curtis Maloney wrote:
Annoying, yes... but that's the way somebody chose to go. I don't know why, but it's there. In fact, if anyone could give me a good reason why it is this way, I would be most appreciative.
In the beginning, there was DTML. DTML did not have expressions as was designed to look very much like HTML, so names like sequence-item were chosen. Later on, expressions were added. Names like 'sequence-item' were obviously not going to do, because in a python expression it looks like a subtraction. So, the DTML namespace was given the name _, and given a mapping interface which allowed you to look up names in the namespace. Thus was born _['sequence-item']. _ is a mapping like any other. It's really not that bad, just kinda ugly. -Michel
participants (4)
-
Curtis Maloney -
Daniel.Weber@SEMATECH.Org -
Kevin Dangoor -
Michel Pelletier