Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XlsxWriter instead of xlwt in to_xls_io() #2592

Merged
merged 2 commits into from Mar 11, 2020

Conversation

jnm
Copy link
Member

@jnm jnm commented Mar 11, 2020

XLSX is now used instead of XLS when deploying forms to KoBoCAT and downloading forms as XLSForm. Fixes #2591.

@jnm jnm requested a review from noliveleger March 11, 2020 08:18
@jnm jnm changed the title Use XlsxWriter instead of xlrd in to_xls_io() Use XlsxWriter instead of xlwt in to_xls_io() Mar 11, 2020
XLSX is now used instead of XLS when deploying forms to KoBoCAT
and downloading forms as XLSForm. Fixes #2591.
@jnm jnm force-pushed the 2591-use-xlsxwriter-in-to_xls_io branch from cb68444 to 5dcdce3 Compare March 11, 2020 08:19
Copy link
Contributor

@noliveleger noliveleger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I have some suggestions. Nothing mandatory.

@@ -72,6 +72,7 @@ unicodecsv
uWSGI
xlrd
xlwt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we like to replace xlwt everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I left xlwt in sync_kobocat_xforms because I thought that maybe xlwt is faster than XlsxWriter, and that XLS files are generally smaller than XLSX—but I haven't tested my assumptions.

Probably what would be better is to convert directly from CSV to KPI asset JSON instead of using XLS(X) at all:

# Convert the xlsform to KPI JSON
xls_io = io.BytesIO(response.content)
if xform.xls.name.endswith('.csv'):
dict_repr = xls2json_backends.csv_to_dict(xls_io)
xls_io = _convert_dict_to_xls(dict_repr)
asset_content = _xlsform_to_kpi_content_schema(xls_io)
return asset_content

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.
Let's keep this for later then.

self.get_object().uid,
request.accepted_renderer.format
)
] = 'attachment; filename={}'.format(filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about f-string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it'd be better, but I see myself having to backport this to Python 2 😐

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the above comment. Let's keep the change for later (after python2 support drop).
PS: I won't repeat this 4 times :P

filename = '.'.join((self.get_object().uid, 'xlsx'))
response[
'Content-Disposition'
] = 'attachment; filename={}'.format(filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about f-string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it'd be better, but I see myself having to backport this to Python 2 😐

Comment on lines +560 to +562
filename = '.'.join(
(self.get_object().uid, request.accepted_renderer.format)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about f-string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it'd be better, but I see myself having to backport this to Python 2 😐

if isinstance(request.accepted_renderer, XlsRenderer):
# `accepted_renderer.format` is 'xls' here for historical
# reasons, but what we actually serve now is xlsx (Excel 2007+)
filename = '.'.join((self.get_object().uid, 'xlsx'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about f-string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it'd be better, but I see myself having to backport this to Python 2 😐

@noliveleger noliveleger merged commit a69e5af into two-databases Mar 11, 2020
@noliveleger noliveleger deleted the 2591-use-xlsxwriter-in-to_xls_io branch March 11, 2020 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants