[Zope] RESPONSE.write(text) and RESPONSE.flush()

Joe Goldthwaite joe at goldthwaites.com
Tue May 11 20:31:08 EDT 2004


Hello All,

I've been chugging along trying to get my Zope application working.  Things
are going pretty well.  My clients are really happy with the results which
is good because they haven't canceled the project.  This was my only hope
for getting Python (or any other non-Microsoft) programming in the door.  So
far, so good.

I've got an external method that rebuilds a reporting database.  I wanted to
send a text string each time a segment of the job finishes.  Here's what I
tried;

jobs = [["job desc 1","some sql statement"],["job desc 2","another sql
statement"]]

def Build(RESPONSE, DBConnection):

	for job in jobs:
		RESPONSE.write(job[0] + "\n")
		RESPONSE.flush()
		DBConnection.cursor.execute(job[0])

	RESPONSE.write("Done!  User your back button to return to the previous
page.\n")

This works but not as well as I hoped.   There are so many jobs that the
final result is off the bottom of the page so if the user doesn't scroll
down, he can't see that its done.  I also wanted to display the data on a
formatted HTML page but it looks like the write function encodes any html so
that you can see it.  This effectively keeps me from producing any kind of
formatted output.  Is there any way to get the write function to return my
text to the browser unchanged?

I also had the great idea of redirecting to a "finished" page with the
command;

RESPONSE.redirect("finished")

Where "finished" is just a simple html page that displays "done" with a link
to return to the home page.  The only problem is that it doesn't work and I
don't know why.  I also tried to return a formatted html page from my
external method after it calls the Build function but it's ignored.  For
some reason, if I call RESPONSE.write(), I can't return any other html to
Zope.

That's confusing so let me illustrate with two functions;


This external method returns a web page that says "This is my web page"

def test1(REQUEST):

	return "<html><head><title>Test 1</title>This is my web page</html>"

This external method only "This is a test"

def test2(REQUEST):

	REQUEST.RESPONSE.write("This is a test\n")
	return "<html><head><title>Test 2</title>This is my web page</html>"

Does anyone understand what's happing and can explain it to me?




More information about the Zope mailing list