backoffice: export ods with a single empty cell if there's nothing (#55330) #715
|
@ -963,6 +963,25 @@ def test_backoffice_ods(pub):
|
|||
)
|
||||
|
||||
|
||||
def test_backoffice_empty_ods(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = []
|
||||
formdef.workflow_roles = {'_receiver': 1}
|
||||
formdef.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/management/form-title/')
|
||||
resp = resp.click('Export a Spreadsheet')
|
||||
resp.form['include_header_line'].checked = False
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.headers['content-type'] == 'application/vnd.oasis.opendocument.spreadsheet'
|
||||
assert resp.body[:2] == b'PK' # ods has a zip container
|
||||
|
||||
|
||||
def test_backoffice_header_line(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
|
|
|
@ -187,8 +187,15 @@ class WorkSheet:
|
|||
root = ET.Element('{%s}table' % NS['table'])
|
||||
root.attrib['{%s}name' % NS['table']] = self.name
|
||||
ET.SubElement(root, '{%s}table-column' % NS['table'])
|
||||
if not self.cells.keys():
|
||||
# empty file, create a spreadsheet with a single empty row
|
||||
self.cells[0] = {}
|
||||
for i in range(0, max(self.cells.keys()) + 1):
|
||||
row = ET.SubElement(root, '{%s}table-row' % NS['table'])
|
||||
if not self.cells.get(i).keys():
|
||||
# no columns here, add a single empty cell
|
||||
ET.SubElement(row, '{%s}table-cell' % NS['table'])
|
||||
|
||||
continue
|
||||
for j in range(0, max(self.cells.get(i).keys()) + 1):
|
||||
cell = self.cells.get(i, {}).get(j, None)
|
||||
if not cell:
|
||||
|
|
Loading…
Reference in New Issue
J'aurais pu plutôt que le self.cells[0] = {} ajouter le nécessaire pour qu'une cellule vide soit vue ici mais j'ai fait ainsi pour qu'une autre situation où ça serait vide soit traitée, si jamais ça arrivait. (j'ai cherché dans le code une possibilité de le provoquer mais je n'ai pas trouvé).