[Zope] Python Script woes

Thomas B. Passin tpassin@mitretek.org
Tue, 15 Jan 2002 17:18:11 -0500


[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