jsoncell: copy Content-Disposition in raw cell's actions (#53666)

This commit is contained in:
Benjamin Dauvergne 2021-05-03 13:05:24 +02:00
parent b5463fb46a
commit d623ff4d8e
2 changed files with 29 additions and 1 deletions

View File

@ -144,7 +144,12 @@ def ajax_page_cell(request, page_pk, cell_reference):
)
if action_response:
return HttpResponse(action_response.content, content_type=action_response.headers['Content-Type'])
response = HttpResponse(
action_response.content, content_type=action_response.headers['Content-Type']
)
if 'Content-Disposition' in action_response.headers:
response['Content-Disposition'] = action_response.headers['Content-Disposition']
return response
if not request.is_ajax():
return HttpResponseRedirect(cell.page.get_online_url())

View File

@ -733,6 +733,11 @@ def test_post_cell(app):
'method': 'GET',
'response': 'raw',
},
'download': {
'url': 'http://test-post-cell/{{slug}}/download/',
'method': 'GET',
'response': 'raw',
},
},
}
},
@ -821,6 +826,24 @@ def test_post_cell(app):
assert requests_search.call_args[0][1] == 'http://test-post-cell/slug/search/'
assert resp2.json == {'foo': 'bar'}
# check raw result with content-disposition
with mock.patch('combo.utils.requests.request') as requests_search:
resp.form['action'] = 'download'
requests_search.return_value = mock.Mock(
content=b'a,b\n1,2',
status_code=200,
headers={
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename=table.csv',
},
)
resp2 = resp.form.submit()
assert requests_search.call_args[0][0] == 'GET'
assert requests_search.call_args[0][1] == 'http://test-post-cell/slug/download/'
assert resp2['Content-Type'] == 'application/octet-stream'
assert resp2['Content-Disposition'] == 'attachment; filename=table.csv'
assert resp2.content == b'a,b\n1,2'
def test_familyinfos_cell_with_placeholders(app, admin_user):
Page.objects.all().delete()