[Zope-DB] Drop down menu from SQL query in dtml method
Charlie Clark
charlie@begeistert.org
Thu, 24 Jul 2003 12:00:46 +0200
On 2003-07-24 at 00:07:08 [+0200], Robert Crotty wrote:
> Charlie,
>
> I am using the basic add entry form structure and result methods as
> follows:
removed and text reorderd.
> What I want to do is add a drop down choice for the partname (part
> number) because it is updated in the MS Access database frequently.. I
> will then change this so the description and unit price is pull from
> access versus all manual entry.
Sure. This is very easy with ZPT (tal:repeat), we just need an appropriate
ZSQL-method. Let's call it qPartname:
SELECT PARTNAME from tWorkorderParts
This will give us a list-like object back where we can list the various
parts following the following scheme.
<p tal:repeat="result here/qPartname"
tal:content="result/PARTNAME">Partname goes here</p>
Try this to get a feel for it. Using this in a pull-down is a little bit
more tricky as it involves setting attributes and not the content.
<form action="process" method=post">
<select name="partname">
<option tal:repeat="result here/qPartname" tal:attributes="value
result/PARTNAME">
</select>
...rest of your form...
</form>
For your migration you can put the ZPT you create inside a DTML-doc/method
which might make things easier.
> The result form looks like this:
This is where ZPT and DTML vary. As Jim Penny has stated, ZPT is
presentation only so this insert should not be in a ZPT. You can keep it in
a DTML-method but I would encourage you to use a PythonScript to check the
contents, maybe raise an error or do the insert, set the flags
appropriately and use
<p tal:condition="exists: request/errors">There was an error</p>
<p tal:condition="not: request/errors">Everything went fine</p>
Or some more refined error handling... This form is currently redundant as
it is - you should simply return to the entry form with the appropriate
message.
The script would be a bit like
### request = context.REQUEST
tInsert = {}
for name, value in request.form.items():
tInsert[name] = value
try:
addRecord1(tInsert)
except:
errors = 1
return context.index_html(context, request)
Hope that gets you started
Charlie