[Zope] Python Script woes

Wade Pearce Wade.Pearce@dpac.tas.gov.au
Wed, 16 Jan 2002 08:18:16 +1100


This is a MIME message. If you are reading this text, you may want to 
consider changing to a mail reader or gateway that understands how to 
properly handle MIME multipart messages.

--=_39644CB5.B4D5BE4A
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

G'day,

I'm trying to develope some Python scripts to help me out with a website.  =
Actually, I'm trying to do it on two sites, but if I get it sorted out on =
the harder one, the other should be a cinch.

Anyway, on this site I have a number of form fields that I want to insert =
into a Postgres table.  Now, unfortunately, because I'm adding to existing =
functionality I can't use the form's standard GET or POST functions to =
produce some form items for my Z SQL Method.  I have used a self.location=
=3DURL for an onClick property on a SAVE ORDER button to post the values =
to another page.  The only problem with this method is that redirecting =
the user back to the main page requires them to sit through the load =
process again (the page, pull-down lists, etc. are all pre-loaded).

So, I want to make the onClick property of the SAVE ORDER button call an =
external Python script that will insert the data.  The problem I'm facing =
is how to do this and how to write the python script.

Basically, the values for the parameters will be:

cust_id (obtained from <dtml-call "REQUEST.set('cust_id', AUTHENTICATED_USE=
R.getUserName())">)
order_body (obtained from document.customer_form.Order.value)
email_address (obtained from document.customer_form.email_address.value)
cust_order_no (obtained from document.customer_form.order_number.value)

How would I call the python script?

A python script I wrote contained one line:

data=3Dcontext.db_customer.method_test("insert into saved_orders values =
('" + cust_id + "','" + order_body + "','" + email_address + "','" + =
cust_order_no + "')")

db_customer is the Pygresql DB connector.

This inserts the data, but hangs while testing.  I was unsuccessful in my =
attempts to call it from the onClick property.  I'm am positive I've =
missed something, and my hours of searching on the web have netted no =
working results.

So, what I am trying to find out is one of the following:

1) Can you do a straight insert via Python.  If so, whats the proper =
syntax
2) Would it be better to call the original Z SQL Method from Python?  Is =
this possible?
3) Am I looking at this from the wrong direction?

Any help greatly appreciated.

Wade Pearce

--=_39644CB5.B4D5BE4A
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR></HEAD>
<BODY style=3D"MARGIN-TOP: 2px; FONT: 10pt Tahoma; MARGIN-LEFT: 2px">
<DIV>G'day,</DIV>
<DIV>&nbsp;</DIV>
<DIV>I'm trying to develope some Python scripts to help me out with a=20
website.&nbsp; Actually, I'm trying to do it on two sites, but if I get =
it=20
sorted out on the harder one, the other should be a cinch.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Anyway, on this site I have a number of form fields that I want to =
insert=20
into a Postgres table.&nbsp; Now, unfortunately, because I'm adding to =
existing=20
functionality&nbsp;I can't use the form's standard GET or POST functions =
to=20
produce some form items for my Z SQL Method.&nbsp; I&nbsp;have used a=20
self.location=3DURL for an onClick property on a SAVE ORDER button to post =
the=20
values to another page.&nbsp; The only problem with this method is that=20
redirecting the user back to the main page requires them to sit through =
the load=20
process again (the page, pull-down lists, etc. are all pre-loaded).</DIV>
<DIV>&nbsp;</DIV>
<DIV>So, I want to make the onClick&nbsp;property of the SAVE ORDER button =
call=20
an external Python script that will insert the data.&nbsp; The problem =
I'm=20
facing is how to do this and how to write the python script.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Basically, the values for the parameters will be:</DIV>
<DIV>&nbsp;</DIV>
<DIV>cust_id (obtained from &lt;dtml-call "REQUEST.set('cust_id',=20
AUTHENTICATED_USER.getUserName())"&gt;)</DIV>
<DIV>order_body (obtained from document.customer_form.Order.value)</DIV>
<DIV>email_address (obtained from=20
document.customer_form.email_address.value)</DIV>
<DIV>cust_order_no (obtained from=20
document.customer_form.order_number.value)</DIV>
<DIV>&nbsp;</DIV>
<DIV>How would I call the python script?</DIV>
<DIV>&nbsp;</DIV>
<DIV>A python script I wrote contained one line:</DIV>
<DIV>&nbsp;</DIV>
<DIV>data=3Dcontext.db_customer.method_test("insert into saved_orders =
values ('" +=20
cust_id + "','" + order_body + "','" + email_address + "','" + cust_order_n=
o +=20
"')")</DIV>
<DIV>&nbsp;</DIV>
<DIV>db_customer is the Pygresql DB connector.</DIV>
<DIV>&nbsp;</DIV>
<DIV>This inserts the data, but hangs while testing.&nbsp; I was unsuccessf=
ul in=20
my attempts to call it from the onClick property.&nbsp; I'm am positive =
I've=20
missed something, and my hours of searching on the web have netted no =
working=20
results.</DIV>
<DIV>&nbsp;</DIV>
<DIV>So, what I am trying to find out is one of the following:</DIV>
<DIV>&nbsp;</DIV>
<DIV>1) Can you do a straight insert via Python.&nbsp; If so, whats the =
proper=20
syntax</DIV>
<DIV>2) Would it be better to call the original Z SQL Method from =
Python?&nbsp;=20
Is this possible?</DIV>
<DIV>3) Am I looking at this from the wrong direction?<BR><BR>Any help =
greatly=20
appreciated.</DIV>
<DIV><BR>Wade Pearce</DIV></BODY></HTML>

--=_39644CB5.B4D5BE4A--