From 16cd94dfa0e892576f1c566948b775b954f7f508 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 9 Oct 2020 03:04:30 +0300 Subject: Fix export function on traits and analysis page * wqflask/wqflask/views.py (export_trait_excel): Write data as bytes instead of strings. See: https://stackoverflow.com/questions/32075135/python-3-in-memory-zipfile-error-string-argument-expected-got-bytes * wqflask/wqflask/show_trait/export_trait_data.py: Convert cmp function into a key function. --- wqflask/wqflask/show_trait/export_trait_data.py | 4 ++-- wqflask/wqflask/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py index 2d76b935..f2132966 100644 --- a/wqflask/wqflask/show_trait/export_trait_data.py +++ b/wqflask/wqflask/show_trait/export_trait_data.py @@ -1,7 +1,7 @@ import simplejson as json from pprint import pformat as pf - +from functools import cmp_to_key from base.trait import create_trait from base import data_set @@ -46,7 +46,7 @@ def get_export_metadata(trait_id, dataset_name): def dict_to_sorted_list(dictionary): sorted_list = [item for item in list(dictionary.items())] - sorted_list = sorted(sorted_list, cmp=cmp_samples) + sorted_list = sorted(sorted_list, key=cmp_to_key(cmp_samples)) sorted_values = [item[1] for item in sorted_list] return sorted_values diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index e8d17613..c37be418 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -376,7 +376,7 @@ def export_trait_excel(): logger.info("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data))) - buff = io.StringIO() + buff = io.BytesIO() workbook = xlsxwriter.Workbook(buff, {'in_memory': True}) worksheet = workbook.add_worksheet() for i, row in enumerate(sample_data): -- cgit v1.2.3