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=URL 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_USER.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=context.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