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
[Wade Pearce] 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. [me] I'd suggest that this isn't really what you should be doing. The problem you have described is really a user interface problem, and should be solved by working with the interface (i.e., the browser): If you notify the user by replacing his form page, it's annoying because it's awkward for the user to get back to where he was. There is another angle to this: if you don't notify the user what happened, she won't know if it succeeded, which is very annoying too. There are basically two things you can do that don't involve scripting, and even with scripting you still have to call something to dispatch the script, so that doesn't really solve the problem. You can 1) Return an HTTP code of 204, and do NOT return any characters (except a blank line to tell the receiver that the headers are finished). This way, the browser knows not to change the page, so your original page does not get replaced. This method gives no feedback to the user about success. 2) Use frames, and save one of them for a report on the success. This is accomplished by making that frame the target of the form. 3) Pop up another window that reports the succes of the operation. Although this too can be annoying, you can make it close automatically when the user clicks outside the window with a bit of javascript: <body onBlur='window.close()'> You could refine this by having the popup window a) be very small 2) Notify the main window of the status, and have the main window display it in the status bar, and/or C) have the popup window immediately bring the main window to the front so it will be visible for just a moment. I recommend some variation on C), and I have used the other two from time to time. Cheers, Tom P
participants (2)
-
Thomas B. Passin -
Wade Pearce