...
 
Commits (4)
......@@ -11,7 +11,7 @@ class CsvWriter:
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding='utf-8', **kwargs):
def __init__(self, f, dialect=csv.excel, **kwargs):
# Redirect output to a queue
self.queue = StringIO()
self.writer = csv.writer(self.queue,
......@@ -38,6 +38,7 @@ class CsvWriter:
self.stream.write(data)
# empty queue
self.queue.truncate(0)
self.queue.seek(0)
def writerows(self, rows):
for row in rows:
......
......@@ -73,7 +73,7 @@ class ExportCsvService(object):
# Filter sessions with reaponses
sessions = ResponseSheet.objects\
.filter(questionnaire__id=uuid, session__isnull=False, response_count__gt=0, preview=False)\
.filter(questionnaire__id=uuid, session__isnull=False, preview=False)\
.values_list('session', flat=True)
responses = Response.objects\
......@@ -283,6 +283,9 @@ class ExportCsvService(object):
filename_zip = '{}_{}_geoexport.zip'.format(slugify(questionnaire.name)[:50], date)
filenames = ExportCsvService.geoquestionnaire_to_csv(questionnaire)
if (len(filenames) == 0):
return None, None
s = BytesIO()
with zipfile.ZipFile(s, "w") as zf:
for fpath in filenames:
......@@ -299,7 +302,7 @@ class ExportCsvService(object):
date = datetime.now().strftime("%Y-%m-%d")
filename = '{}_{}.csv'.format(slugify(questionnaire.name)[:50], date)
stream = StringIO()
with open(filename, 'w') as csv_file:
with open(filename, 'w', encoding='utf-8') as csv_file:
writer = CsvWriter(stream)
writer.writerows(
ExportCsvService.questionnaire_to_csv(questionnaire))
......@@ -314,10 +317,10 @@ class ExportCsvService(object):
date = datetime.now().strftime("%Y-%m-%d")
filename_zip = '{}_{}.zip'.format(slugify(questionnaire.name)[:50], date)
filenames = (geoexport_zip_name, regular_export_csv_filename)
zip_stream = BytesIO()
with zipfile.ZipFile(zip_stream, 'w') as zip_file:
zip_file.writestr(os.path.basename(regular_export_csv_filename), regular_export_csv)
zip_file.writestr(os.path.basename(geoexport_zip_name), geoexport_zip)
if geoexport_zip is not None and geoexport_zip_name is not None:
zip_file.writestr(os.path.basename(geoexport_zip_name), geoexport_zip)
zip_file.close()
return zip_stream.getvalue(), filename_zip
......@@ -176,6 +176,8 @@ class Response(models.Model):
return 'nd' if self.value_number is None else self.value_number
elif self.input.widget == 'drawbutton' and self.value_geometry:
return self.value_geometry.wkt
elif self.input.widget == 'userimage' and self.value_image:
return self.value_image.name
return self.value_text
......
......@@ -580,7 +580,7 @@ class ImageInput(Input):
class UserImageInput(Input):
RESPONSE_COLUMN_NAME = 'value_image'
EXPORTABLE = False
EXPORTABLE = True
GEO_EXPORTABLE = False
"""
This is a proxy model for the user image inputs
......