diff --git a/combo/public/views.py b/combo/public/views.py index 1d568838..a4f016f1 100644 --- a/combo/public/views.py +++ b/combo/public/views.py @@ -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()) diff --git a/tests/test_public.py b/tests/test_public.py index 4203ba5f..2f4f9f0c 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -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()