From: Guillaume Pellerin Date: Fri, 22 Jan 2016 16:47:23 +0000 (+0100) Subject: fix csv export command, add more deps X-Git-Tag: 1.6b~6^2~5 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=f9be9642a0196d7dea4a0f7ee6382dfba1ab11fc;p=telemeta.git fix csv export command, add more deps --- diff --git a/setup.py b/setup.py index 7fa75c1b..d85c9f4d 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,8 @@ setup( '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 58207222..2fc56230 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 @@ import timeside.core 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()