Have your 'export' button make an AJAX call to a view, which creates the CSV
file and prompts the user to 'Save As.'
Details:
1. Use the same view you currently have, with an 'if' statement which
returns a standard (html) response or a CSV file based on a slug in your URL.
2. You're going to have to re-submit the parameters in your AJAX call.
I recommend just using jQuery's serialize() and .post() to do this with no
sweat.
3. An HTTP response is a file-like object. Save your CSV to it. You'll
also need to change the contenttype. Great example here:
http://docs.djangoproject.com/en/1.1/howto/outputting-csv/
End result: Someone runs your report. They see the results. They click the
'Export CSV button/link/graphic,' and they're prompted by their browser to save
a CSV file without leaving the page they're on.
I'm doing almost exactly this, with the exception that I'm providing an Excel
spreadsheet (xlwt module instead of csv and a different contenttype).
Shawn
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.