ods: use float columns for numbers (#16667)

This commit is contained in:
Frédéric Péters 2017-06-15 13:35:16 +02:00
parent 3804bfbcc7
commit ab28fdfc93
2 changed files with 18 additions and 0 deletions

View File

@ -790,12 +790,14 @@ def test_backoffice_ods(pub):
formdef = FormDef.get_by_urlname('form-title')
formdef.fields.append(fields.FileField(id='4', label='file field', type='file'))
formdef.fields.append(fields.DateField(id='5', label='date field', type='date'))
formdef.fields.append(fields.StringField(id='6', label='number field', type='string'))
formdef.store()
formdata = formdef.data_class().select(lambda x: x.status == 'wf-new')[0]
formdata.data['4'] = PicklableUpload('/foo/bar', content_type='text/plain')
formdata.data['4'].receive(['hello world'])
formdata.data['5'] = time.strptime('2015-05-12', '%Y-%m-%d')
formdata.data['6'] = '12345'
formdata.store()
resp = app.get('/backoffice/management/form-title/')
@ -815,6 +817,7 @@ def test_backoffice_ods(pub):
all_texts = [x.text for x in ods_sheet.findall('.//{%s}table-row//{%s}p' % (ods.TABLE_NS, ods.TEXT_NS))]
created_column = all_texts.index('Created')
date_column = all_texts.index('date field')
number_column = all_texts.index('number field')
for row in ods_sheet.findall('.//{%s}table-row' % ods.TABLE_NS):
if row.findall('.//{%s}table-cell/{%s}p' % (
@ -831,6 +834,10 @@ def test_backoffice_ods(pub):
'{%s}value-type' % ods.OFFICE_NS] == 'date'
assert row.findall('.//{%s}table-cell' % ods.TABLE_NS)[date_column].attrib[
'{%s}style-name' % ods.TABLE_NS] == 'Date'
assert row.findall('.//{%s}table-cell' % ods.TABLE_NS)[number_column].attrib[
'{%s}value-type' % ods.OFFICE_NS] == 'float'
assert row.findall('.//{%s}table-cell' % ods.TABLE_NS)[number_column].attrib[
'{%s}value' % ods.OFFICE_NS] == '12345'
def test_backoffice_statistics(pub):
create_superuser(pub)

View File

@ -32,6 +32,14 @@ TEXT_NS = 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'
XLINK_NS = 'http://www.w3.org/1999/xlink'
def is_number(value):
try:
float(value)
except ValueError:
return False
return True
class Workbook(object):
def __init__(self, encoding='utf-8'):
self.sheets = []
@ -183,5 +191,8 @@ class WorkCell(object):
root.attrib['{%s}value-type' % OFFICE_NS] = 'date'
root.attrib['{%s}date-value' % OFFICE_NS] = make_date(self.native_value).strftime('%Y-%m-%d')
p.text = make_datetime(self.native_value).strftime(date_format())
elif is_number(self.value):
root.attrib['{%s}value-type' % OFFICE_NS] = 'float'
root.attrib['{%s}value' % OFFICE_NS] = str(self.value)
return root