Skip to content

Commit

Permalink
fix csv export command, add more deps
Browse files Browse the repository at this point in the history
  • Loading branch information
yomguy committed Jan 22, 2016
1 parent 5315cce commit f9be964
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions setup.py
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions telemeta/management/commands/telemeta-export-all-to-csv.py
Expand Up @@ -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):
Expand All @@ -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()

0 comments on commit f9be964

Please sign in to comment.