def render_to_response(self, context, **response_kwargs): qs = context['filter'].qs.values() file_buffer = export_targets(qs) file_buffer.seek(0) # goto the beginning of the buffer response = StreamingHttpResponse(file_buffer, content_type="text/csv") filename = "targets-{}.csv".format(slugify(datetime.utcnow())) response['Content-Disposition'] = 'attachment; filename="{}"'.format( filename) return response
def render_to_response(self, context, **response_kwargs): """ Returns a response containing the exported CSV of selected targets. :param context: Context object for this view :type context: dict :returns: response class with CSV :rtype: StreamingHttpResponse """ qs = context['filter'].qs.values() file_buffer = export_targets(qs) file_buffer.seek(0) # goto the beginning of the buffer response = StreamingHttpResponse(file_buffer, content_type="text/csv") filename = "targets-{}.csv".format(slugify(datetime.utcnow())) response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename) return response