You might be able to add a Javascript event handler that triggers a client
side redirect as well as a file download (via window.open). Something like
this:
{{=A('Download Excel file', _href='', _id='download')}}
<script>
jQuery(function() {
jQuery('#download').click(function(e) {
window.open('{{=URL('default', 'download_excel')}}');
window.location = '{{=URL('default', 'some_other_action')}}';
e.preventDefault();
});
});
</script>
window.open will open a new tab, but if the request returns a file to be
downloaded, it will switch to a file download dialog (and the tab should
automatically close after download). window.location will simultaneously
redirect the original page to the new URL.
Anthony
On Wednesday, December 12, 2012 2:51:21 PM UTC-5, Jim S wrote:
>
> I'm looking for a way to return an Excel sheet to the user and then
> redirect to a different page all in the same request.
>
> Here is what I'm doing now:
>
> from reports import movementDetail as rpt
> letters_file = StringIO.StringIO()
> returnVal = rpt.process(originationId, fromDate, toDate, letters_file,auth
> .user.id)
> if returnVal:
> excelFile = letters_file.getvalue()
> letters_file.close()
> response.headers['Content-Type']='application/vnd.ms-excel'
> return(excelFile)
> else:
> response.flash = 'No movements for specific origin in date range.'
> return dict(form=form)
>
> When I do the return(excelFile) I somehow would like to pass a URL that it
> would redirect to when the excel sheet is returned. Any ideas? I'm
> guessing there is something simple I'm missing.
>
> -Jim
>
--