*example with a button. You can put the button in SQLFORM.factory:*
def index():
# in an new tab
# *_target='_blank'*
* # set start and end for example with SQLFORM.factory*
button = A('create a pdf-report in an new tab', _class="btn" ,
_title=T("create PDF-report"), _href=URL("default","result"), args=[start,
end]), *_target='_blank'*)
return dict(button=button)
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
Am Mittwoch, 23. April 2014 15:55:50 UTC+2 schrieb csavorgn:
> 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
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.