Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created June 18, 2016 04:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/f6784c7a1e07a8533e86c0a40493183d to your computer and use it in GitHub Desktop.
Save sivabudh/f6784c7a1e07a8533e86c0a40493183d to your computer and use it in GitHub Desktop.
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