Merge "Removing check for unsupported Django version"

changes/49/207549/15
Jenkins 7 years ago committed by Gerrit Code Review
commit 8d008a73c4
  1. 65
      horizon/utils/csvbase.py

@ -17,8 +17,8 @@ from csv import writer # noqa
from django.http import HttpResponse # noqa
from django.http import StreamingHttpResponse # noqa
from django import template as django_template
from django import VERSION # noqa
import six
from six import StringIO
@ -99,47 +99,42 @@ class BaseCsvResponse(CsvDataMixin, HttpResponse):
return []
if VERSION >= (1, 5, 0):
class BaseCsvStreamingResponse(CsvDataMixin, StreamingHttpResponse):
from django.http import StreamingHttpResponse # noqa
"""Base CSV Streaming class. Provides streaming response for CSV data."""
class BaseCsvStreamingResponse(CsvDataMixin, StreamingHttpResponse):
"""Base CSV Streaming class. Provides streaming response for CSV data.
"""
def __init__(self, request, template, context, content_type, **kwargs):
super(BaseCsvStreamingResponse, self).__init__()
self['Content-Disposition'] = 'attachment; filename="%s"' % (
kwargs.get("filename", "export.csv"),)
self['Content-Type'] = content_type
self.context = context
self.header = None
if template:
# Display some header info if provided as a template
header_template = django_template.loader.get_template(template)
context = django_template.RequestContext(request, self.context)
self.header = header_template.render(context)
def __init__(self, request, template, context, content_type, **kwargs):
super(BaseCsvStreamingResponse, self).__init__()
self['Content-Disposition'] = 'attachment; filename="%s"' % (
kwargs.get("filename", "export.csv"),)
self['Content-Type'] = content_type
self.context = context
self.header = None
if template:
# Display some header info if provided as a template
header_template = django_template.loader.get_template(template)
context = django_template.RequestContext(request, self.context)
self.header = header_template.render(context)
self._closable_objects.append(self.out)
self._closable_objects.append(self.out)
self.streaming_content = self.get_content()
self.streaming_content = self.get_content()
def buffer(self):
buf = self.out.getvalue()
self.out.truncate(0)
return buf
def buffer(self):
buf = self.out.getvalue()
self.out.truncate(0)
return buf
def get_content(self):
if self.header:
self.out.write(self.encode(self.header))
def get_content(self):
if self.header:
self.out.write(self.encode(self.header))
self.write_csv_header()
yield self.buffer()
self.write_csv_header()
for row in self.get_row_data():
self.write_csv_row(row)
yield self.buffer()
for row in self.get_row_data():
self.write_csv_row(row)
yield self.buffer()
def get_row_data(self):
return []
def get_row_data(self):
return []

Loading…
Cancel
Save