Hi everyone,
I'm using a SQLFORM.factory to get the data I need to generate a PDF file using ReportLab.
I'm using a submit button to check for the data entered and to open a new page using redirect:
redirect(URL("default","result", vars=dict(start=form.vars.date_start,
end=form.vars.date_end)))
In the controller default.py I defined
def result():
start = request.vars['start']
end = request.vars['end']
filename = os.path.join(request.folder,'private',str(uuid4()))
create_pdf(filename, db, start, end)
response.headers['Content-Type']='application/pdf'
data = open(filename,"rb").read()
os.unlink(filename)
return data
(The code I'm using is more complex than this.)
Maybe it is not the cleanest way to do this, but when I click on the button the temporary PDF opens on the same tab in the browser.
In my app I would like to get a different behaviour: when I click on the submit button the PDF should open on a new tab. The PDF should be temporary as it is in my current code.
How can I achieve the behaviour I want?
Thanks
Carlo