Re: [Zope] passing a zope <dtml-in...> list element to a sql method
Dieter, thank you for responding. I made several attempts based on my understanding of your answer and I still am not getting it right. Here is the situation as I last tried it: "category", as passed to the form action, is a list generated by the user selecting multiple items from a listbox. --------------------------------------------------- from my form: (this part works fine) --------------------------------------------------- <tr><td><select name="category" size="10" multiple> <dtml-in sql_get_categories> <option value="<dtml-var category>" > <dtml-var category> </dtml-in> ---------------------------- from my form action ---------------------------- <dtml-in category prefix=test> <dtml-comment>this is the list</dtml-comment> <dtml-call name="sql_delete_a_category(trash='<dtml-var test_item>')"> <dtml-var test_item><br> <dtml-comment>used to verify items are looping</dtml-comment> </dtml-in> --------------------------------------- my SQL: (nothing happens) --------------------------------------- Arguments: trash delete from categories where category = '<dtml-var name="trash" sql_quote>' What am I doing wrong? My SQL returns with no error but doesn't delete the items I think I am passing. Thank you for your continued help. Roger Mallett
From: Dieter Maurer <dieter@handshake.de> To: "Roger Mallett" <rogermallett@hotmail.com> CC: zope@zope.org Subject: Re: [Zope] passing a zope <dtml-in...> list element to a sql method Date: Sun, 28 Sep 2003 22:31:17 +0200
Roger Mallett wrote at 2003-9-28 05:33 +0000:
I am attempting to access an element from a list and pass the element to a SQL method.
If "l" is a list, you access its "i"th element with "l[i]".
To pass an argument to a Z SQL Method, you pass it as keyword argument: "YourZSQLMethod(argument1=val1, argument2=val2,...)".
Dieter
_________________________________________________________________
On Mon, 2003-09-29 at 02:05, Roger Mallett wrote: <snip>
<dtml-call name="sql_delete_a_category(trash='<dtml-var test_item>')">
I doubt you want to pass a *string* representing a DTML tag... more likely, you wanted to pass the *value* of the variable, yes?
delete from categories where category = '<dtml-var name="trash" sql_quote>'
Here, your syntax is wrong. There is no "name" property of a DTML tag. Try these in their respective spots: <dtml-call name="sql_delete_a_category(trash=test_item)"> delete from categories where category = '<dtml-var trash sql_quote>' HTH, Dylan
<dtml-in category prefix=test> <dtml-comment>this is the list</dtml-comment>
<dtml-call name="sql_delete_a_category(trash='<dtml-var test_item>')"> <dtml-var test_item><br> <dtml-comment>used to verify items are looping</dtml-comment> </dtml-in>
The nested tag nature of DTML seems to have confused you as to how it actually works. One cannot put a DTML tag inside a DTML tag, though you can put DTML tags inside HTML tags. It's an easy mistake to make in clear languages, and especially in DTML. Think of it as a two-pass process. Zope does the first pass and renders everything that looks like DTML. The output then should be HTML, which is given to the browser for a second pass. Note that there's no room here for a DTML tag inside a DTML tag to be rendered such that its results can be used in a DTML tag. Or imagine that a DTML tag is a Python print statement. You can't do: print "this is the contents of variable print a" when you mean print "this is the contents of variable " + a And for an entry to the ZPT v. DTML debate, it's a lot clearer what to do in ZPT: <span tal:repeat="test somewhere/category"> <tal:call tal:define="dummy python:sql_delete_a_category(trash=repeat.test)" /> <span tal:replace="repeat/test" /> </span> I refer you also to the threads (one old, one new):: "rendered method in dtml document" and "testing with dtml-if" --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
participants (3)
-
Dylan Reinhardt -
J. Cameron Cooper -
Roger Mallett