Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example python code for our SR export
rows = export_order_csv(request.POST)
# nested method used only in this method to return a yield encoded data first the yield csv code later
def response_generator():
yield u'\ufeff'.encode('utf8')
for row in rows:
yield writer.writerow(row)
pseudo_buffer = Echo()
writer = csv.writer(pseudo_buffer)
response = StreamingHttpResponse(response_generator(), content_type="application/force-download; charset=utf-8")
filename = unicode(_("Accepted_Order_Data_")) + unicode(timezone.now().date().strftime('%y%m%d'))
response['Content-Disposition'] = 'attachement; filename="{0}.csv"'.format(filename)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment