From c92f45b7c59faf3ac2d54f04d717659ae65c32e1 Mon Sep 17 00:00:00 2001 From: Hilbert Schraal Date: Mon, 26 Oct 2015 19:50:35 +0100 Subject: [PATCH 1/2] Add the ability to specify the dialect. --- separated/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/separated/views.py b/separated/views.py index 93562ab..016a636 100644 --- a/separated/views.py +++ b/separated/views.py @@ -38,6 +38,7 @@ class CsvResponseMixin(MultipleObjectMixin): columns = None output_headers = True filename = '{model_name}_list.csv' + dialect = csv.excel def render_to_response(self, context, **kwargs): queryset = context['object_list'] @@ -46,7 +47,7 @@ def render_to_response(self, context, **kwargs): filename=self.get_filename(model), ) - writer = csv.writer(response) + writer = csv.writer(response, dialect=self.dialect) if self.output_headers: writer.writerow(self.get_header_row(model)) From b4e57bf9dbcc7ae962e0d5543a18ce6e9d1eafbf Mon Sep 17 00:00:00 2001 From: Hilbert Schraal Date: Mon, 26 Oct 2015 20:03:19 +0100 Subject: [PATCH 2/2] Add the ability to specify the dialect. Documentation --- README.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.rst b/README.rst index 4fc7790..22d8580 100644 --- a/README.rst +++ b/README.rst @@ -79,6 +79,13 @@ settings the ``filename`` attribute. There is a corresponding By default, ``CsvView`` will output the headers as the first line. If you want to suppress this behavior, set ``output_headers`` to ``False``. +By defaultm ``csv.excel`` is used as the dialect. You can override the by setting +the ``dialect`` attribute. For example:: + + class UserCsvView(CsvView): + model = User + dialect = csv.excel_tab + separated.views.CsvResponseMixin ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~