cleanup: remove legacy support for .xls exports (#48590)

This commit is contained in:
Frédéric Péters 2020-11-16 20:07:19 +01:00
parent ab5226d12b
commit c9bc9f6bf0
5 changed files with 1 additions and 117 deletions

3
debian/control vendored
View File

@ -33,8 +33,7 @@ Recommends: libreoffice-writer-nogui | libreoffice-writer,
python3-langdetect,
python3-magic,
python3-qrcode,
python3-workalendar,
python3-xlwt
python3-workalendar
Suggests: python3-libxml2
Description: web application to design and set up online forms
w.c.s. is a web application which allows to design and set up online forms.

View File

@ -10,11 +10,6 @@ import zipfile
import mock
import pytest
try:
import xlwt
except ImportError:
xlwt = None
from django.utils.six import StringIO, BytesIO
from django.utils.six.moves.urllib import parse as urllib

View File

@ -3,11 +3,6 @@ import os
import pytest
try:
import xlwt
except ImportError:
xlwt = None
from quixote import get_publisher
from wcs.qommon.ident.password_accounts import PasswordAccount
from wcs.qommon.http_request import HTTPRequest

View File

@ -7,11 +7,6 @@ import zipfile
import pytest
try:
import xlwt
except ImportError:
xlwt = None
from django.utils.six import BytesIO
from django.utils.six.moves.urllib import parse as urlparse
@ -486,29 +481,3 @@ def test_backoffice_ods(pub):
'{%s}value' % ods.NS['office']] == '123.45'
assert row.findall('.//{%s}table-cell' % ods.NS['table'])[not_number_column].attrib[
'{%s}value-type' % ods.NS['office']] == 'string'
@pytest.mark.skipif('xlwt is None')
def test_backoffice_xls(pub):
create_superuser(pub)
FormDef.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = []
formdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
assert 'Excel Export' not in resp.text
if not pub.site_options.has_section('options'):
pub.site_options.add_section('options')
pub.site_options.set('options', 'legacy-excel-export', 'true')
fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
pub.site_options.write(fd)
fd.close()
resp = app.get('/backoffice/management/form-title/')
resp = resp.click('Excel Export')
assert resp.headers['content-type'].startswith('application/vnd.ms-excel')

View File

@ -23,11 +23,6 @@ import types
import vobject
import zipfile
try:
import xlwt
except ImportError:
xlwt = None
from django.conf import settings
from django.utils import six
from django.utils.encoding import force_text
@ -1108,9 +1103,6 @@ class FormPage(Directory):
qs, _('Export a Spreadsheet'))
r += htmltext(' <li><a data-base-href="csv" href="csv%s">%s</a></li>') % (
qs, _('Export as CSV File'))
if xlwt and get_publisher().has_site_option('legacy-excel-export'):
r += htmltext('<li><a data-base-href="xls" href="xls%s">%s</a></li>') % (
qs, _('Excel Export'))
if self.formdef.geolocations:
r += htmltext(' <li><a data-base-href="map" href="map%s">%s</a></li>') % (
qs, _('Plot on a Map'))
@ -2134,72 +2126,6 @@ class FormPage(Directory):
'attachment; filename=%s' % job.file_name)
return job.file_content
def xls(self):
self.check_access()
if xlwt is None or not get_publisher().has_site_option('legacy-excel-export'):
raise errors.TraversalError()
fields = self.get_fields_from_query()
selected_filter = self.get_filter_from_query()
user = get_request().user
query = get_request().form.get('q')
criterias = self.get_criterias_from_query()
order_by = misc.get_order_by_or_400(get_request().form.get('order_by', None))
class Exporter(object):
def __init__(self, formpage, formdef, fields, selected_filter):
self.formpage = formpage
self.formdef = formdef
self.fields = fields
self.selected_filter = selected_filter
def export(self, job=None):
w = xlwt.Workbook(encoding=get_publisher().site_charset)
ws = w.add_sheet('1')
for i, f in enumerate(self.formpage.csv_tuple_heading(self.fields)):
ws.write(0, i, f)
items, total_count = FormDefUI(self.formdef).get_listing_items(
fields, self.selected_filter, user=user, query=query,
criterias=criterias, order_by=order_by)
for i, filled in enumerate(items):
for j, item in enumerate(self.formpage.get_spreadsheet_line(fields, filled)):
elem = item['value']
if elem and len(elem) > 32767:
# xls cells have a limit of 32767 characters, cut
# it down.
elem = elem[:32760] + ' [...]'
ws.write(i+1, j, elem)
self.output = BytesIO()
w.save(self.output)
if job:
job.file_content = self.output.getvalue()
job.content_type = 'application/vnd.ms-excel'
job.store()
get_logger().info('backoffice - form %s - as excel' % self.formdef.name)
count = self.formdef.data_class().count()
exporter = Exporter(self, self.formdef, fields, selected_filter)
if count > self.WCS_SYNC_EXPORT_LIMIT:
job = get_response().add_after_job(
str(N_('Exporting forms in Excel format')),
exporter.export)
job.file_name = '%s.xls' % self.formdef.url_name
job.store()
return redirect('export?job=%s' % job.id)
else:
exporter.export()
response = get_response()
response.set_content_type('application/vnd.ms-excel')
response.set_header('content-disposition', 'attachment; filename=%s.xls' % self.formdef.url_name)
return exporter.output.getvalue()
def ods(self):
self.check_access()
if 'anonymise' in get_request().form: