misc: fix csv import of jsonp item fields (#73951) #334
|
@ -390,6 +390,7 @@ def test_backoffice_cards_import_data_from_csv(pub):
|
|||
fields.TextField(id='9', label='Long'),
|
||||
fields.ItemField(id='10', label='List2', data_source=data_source),
|
||||
fields.ItemsField(id='11', label='Items', data_source=data_source, required=False),
|
||||
fields.ItemField(id='12', label='Jsonp', data_source={'type': 'jsonp', 'value': 'xxx'}),
|
||||
]
|
||||
carddef.workflow_roles = {'_editor': user.roles[0]}
|
||||
carddef.workflow = wf
|
||||
|
@ -419,7 +420,7 @@ def test_backoffice_cards_import_data_from_csv(pub):
|
|||
sample_resp = resp.click('Download sample CSV file for this card')
|
||||
today = datetime.date.today()
|
||||
assert sample_resp.text == (
|
||||
'"Table","Map","Test","Boolean","List","Date","File","Email","Long","List2","Items"\r\n'
|
||||
'"Table","Map","Test","Boolean","List","Date","File","Email","Long","List2","Items","Jsonp"\r\n'
|
||||
'"will be ignored - type Table not supported",'
|
||||
'"%s",'
|
||||
'"value",'
|
||||
|
@ -430,7 +431,9 @@ def test_backoffice_cards_import_data_from_csv(pub):
|
|||
'"foo@example.com",'
|
||||
'"value",'
|
||||
'"value",'
|
||||
'"id1|id2|..."\r\n' % (pub.get_default_position(), today)
|
||||
'"id1|id2|...",'
|
||||
'"value"'
|
||||
"\r\n" % (pub.get_default_position(), today)
|
||||
)
|
||||
|
||||
# missing file
|
||||
|
@ -449,10 +452,11 @@ def test_backoffice_cards_import_data_from_csv(pub):
|
|||
resp = resp.forms[0].submit()
|
||||
assert 'CSV file contains less columns than card fields.' in resp.text
|
||||
|
||||
data = [b'Table,Map,Test,Boolean,List,Date,File,Email,Long,List2,Items']
|
||||
data = [b'Table,Map,Test,Boolean,List,Date,File,Email,Long,List2,Items,Jsonp']
|
||||
for i in range(1, 150):
|
||||
data.append(
|
||||
b'table,48.81;2.37,data%d ,%s,item%d,2020-01-%02d,filename-%d,test@localhost,"plop\nplop",1,1|2'
|
||||
b'table,48.81;2.37,data%d ,%s,item%d,2020-01-%02d,filename-%d,'
|
||||
b'test@localhost,"plop\nplop",1,1|2,jsonpval'
|
||||
% (i, str(bool(i % 2)).encode('utf-8'), i, i % 31 + 1, i)
|
||||
)
|
||||
|
||||
|
@ -475,6 +479,8 @@ def test_backoffice_cards_import_data_from_csv(pub):
|
|||
{'id': '1', 'text': 'un', 'more': 'foo'},
|
||||
{'id': '2', 'text': 'deux', 'more': 'bar'},
|
||||
]
|
||||
assert card1.data['12'] == 'jsonpval'
|
||||
assert card1.data['12_display'] == 'jsonpval'
|
||||
assert card2.data['2'] == 'data2'
|
||||
assert card2.data['3'] is False
|
||||
assert card2.data['5'].tm_mday == 3
|
||||
|
|
|
@ -2240,6 +2240,8 @@ class ItemFieldMixin:
|
|||
return get_publisher().translate(value) or ''
|
||||
|
||||
if data_source.type == 'jsonp':
|
||||
if not get_session():
|
||||
return value
|
||||
if not get_session().jsonp_display_values:
|
||||
get_session().jsonp_display_values = {}
|
||||
return get_session().jsonp_display_values.get('%s_%s' % (data_source.get_jsonp_url(), value))
|
||||
|
|
Loading…
Reference in New Issue