From f9be9642a0196d7dea4a0f7ee6382dfba1ab11fc Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Fri, 22 Jan 2016 17:47:23 +0100 Subject: [PATCH] fix csv export command, add more deps --- setup.py | 2 ++ .../commands/telemeta-export-all-to-csv.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 7fa75c1b2..d85c9f4de 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,8 @@ def run_tests(self): 'elasticsearch==1.6.0', 'django-haystack', 'ebooklib', + 'django-environ', + 'redis', ], tests_require=['pytest-django', 'pytest-cov', 'factory-boy'], # Provide a test command through django-setuptest diff --git a/telemeta/management/commands/telemeta-export-all-to-csv.py b/telemeta/management/commands/telemeta-export-all-to-csv.py index 582072226..2fc562304 100644 --- a/telemeta/management/commands/telemeta-export-all-to-csv.py +++ b/telemeta/management/commands/telemeta-export-all-to-csv.py @@ -9,7 +9,7 @@ from timeside.server.models import * from timeside.core.tools.test_samples import generateSamples from telemeta.models import * -from telemeta.util.unicode import * +from telemeta.util.unicode import Echo, UnicodeCSVWriter class Command(BaseCommand): @@ -18,14 +18,17 @@ class Command(BaseCommand): def handle(self, *args, **options): path = args[-1] element_type = args[-2] - f = open(path, 'w') + pseudo_buffer = Echo() + if element_type == "item": elements = MediaItem.objects.all().order_by('id') elif element_type == "collection": elements = MediaCollection.objects.all().order_by('id') else: raise TypeError('type should be "item" or "collection"') - writer = UnicodeWriter(f) - csv = CSVExport(writer) - csv.write(elements) + + f = open(path, 'w') + writer = UnicodeCSVWriter(pseudo_buffer, elements) + for data in writer.output(): + f.write(data) f.close()