Skip to content

Commit

Permalink
Add backward compatibility with existing .xls forms
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <[email protected]>
  • Loading branch information
KipSigei committed Feb 22, 2023
1 parent a8557dd commit b9209ce
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,15 @@ def form(self, request, **kwargs):
)
# pylint: disable=attribute-defined-outside-init
self.etag_data = f"{form.date_modified}"
filename = form.id_string + "." + form_format
response = response_for_format(form, format=form_format)

# add backward compatibility for existing .xls forms
if form_format in XLS_EXTENSIONS:
data = response.data
existing_file_format = data.name.split(".")[-1]
if existing_file_format == 'xls':
form_format = existing_file_format
filename = form.id_string + "." + form_format
response["Content-Disposition"] = "attachment; filename=" + filename

return response
Expand Down

0 comments on commit b9209ce

Please sign in to comment.