Project

General

Profile

Development #53666

Pouvoir définir le nom du fichier attaché retourné par une action de cellule JSON (mode response=raw)

Added by Benjamin Dauvergne 14 days ago. Updated 13 days ago.

Status:
Solution déployée
Priority:
Normal
Target version:
-
Start date:
03 May 2021
Due date:
% Done:

0%

Estimated time:
Patch proposed:
Yes
Planning:
No

Description

La solution la plus évidente serait de simplement recopier l'entête content-disposition s'il y en a un, comme on copie l'entête content-type :

diff --git combo/public/views.py combo/public/views.py
index 21e40c1d..f834d523 100644
--- combo/public/views.py
+++ combo/public/views.py
@@ -144,7 +144,10 @@ 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())

ou alors pour laisser la main plutôt au template qu'au connecteur faire ça au en laissant une partie libre dans l'URL de la vue ajax:

index 7df37d35..d80c2ffc 100644
--- combo/public/urls.py
+++ combo/public/urls.py
@@ -27,6 +27,11 @@ urlpatterns = [
         views.ajax_page_cell,
         name='combo-public-ajax-page-cell',
     ),
+    url(
+        r'^ajax/cell/(?P<page_pk>\d+)/(?P<cell_reference>[\w_]+-\d+)/(?P<filename>[^/]+)$',
+        views.ajax_page_cell,
+        name='combo-public-ajax-page-cell',
+    ),
     url(r'^snapshot/(?P<pk>\w+)/$', manager_required(views.snapshot), name='combo-snapshot-view'),
     url(r'__style__/$', views.style),
     url(r'__skeleton__/$', views.skeleton),
diff --git combo/public/views.py combo/public/views.py
index 21e40c1d..7d32246c 100644
--- combo/public/views.py
+++ combo/public/views.py
@@ -106,7 +106,7 @@ def modify_global_context(request, ctx):

 @csrf_exempt
-def ajax_page_cell(request, page_pk, cell_reference):
+def ajax_page_cell(request, page_pk, cell_reference, filename=None):
     try:
         page = Page.objects.get(id=page_pk)
     except Page.DoesNotExist:
@@ -144,7 +144,10 @@ 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 filename:
+                response['Content-Disposition'] = 'attachment'
+            return response

         if not request.is_ajax():
             return HttpResponseRedirect(cell.page.get_online_url())

Files


Related issues

Related to Combo - Development #53720: test_import_export.test_import_export_pwa_navigation en échec après #53666Solution déployée04 May 2021

Actions

Associated revisions

Revision d623ff4d (diff)
Added by Benjamin Dauvergne 13 days ago

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

History

#2

Updated by Frédéric Péters 14 days ago

Plutôt pas la modif à l'url.

#3

Updated by Benjamin Dauvergne 14 days ago

  • Assignee set to Benjamin Dauvergne
#4

Updated by Benjamin Dauvergne 14 days ago

#5

Updated by Emmanuel Cazenave 14 days ago

  • Status changed from Solution proposée to Solution validée
#6

Updated by Benjamin Dauvergne 13 days ago

  • Status changed from Solution validée to Résolu (à déployer)
commit d623ff4d8efb8b966babe3ceee14f6b9f9cf2d80
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Mon May 3 13:05:24 2021 +0200

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

Updated by Frédéric Péters 13 days ago

  • Related to Development #53720: test_import_export.test_import_export_pwa_navigation en échec après #53666 added
#8

Updated by Frédéric Péters 13 days ago

  • Status changed from Résolu (à déployer) to Solution déployée

Also available in: Atom PDF