Fichiers des chants servis par X-Sendfile
This commit is contained in:
		
							parent
							
								
									c37c52cb5d
								
							
						
					
					
						commit
						75f024feaf
					
				
					 2 changed files with 22 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,9 +1,12 @@
 | 
				
			||||||
from datetime import date, timedelta
 | 
					from datetime import date, timedelta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.conf import settings
 | 
				
			||||||
from django.contrib import messages
 | 
					from django.contrib import messages
 | 
				
			||||||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
 | 
					from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
 | 
				
			||||||
 | 
					from django.http import HttpResponse
 | 
				
			||||||
from django.urls import reverse_lazy
 | 
					from django.urls import reverse_lazy
 | 
				
			||||||
from django.views.generic import (
 | 
					from django.views.generic import (
 | 
				
			||||||
    CreateView, DeleteView, ListView, TemplateView, UpdateView
 | 
					    CreateView, DeleteView, ListView, TemplateView, UpdateView, View
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .forms import ChantEditForm, MembreEditForm
 | 
					from .forms import ChantEditForm, MembreEditForm
 | 
				
			||||||
| 
						 | 
					@ -27,6 +30,22 @@ class ManifestView(TemplateView):
 | 
				
			||||||
    content_type = "application/json"
 | 
					    content_type = "application/json"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MediaServeView(LoginRequiredMixin, View):
 | 
				
			||||||
 | 
					    subdir = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get(self, request, *args, **kwargs):
 | 
				
			||||||
 | 
					        if request.get_host() == "localhost:8000":
 | 
				
			||||||
 | 
					            from django.views.static import serve
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return serve(request, f"{self.subdir}/{kwargs['path']}", document_root=settings.MEDIA_ROOT)
 | 
				
			||||||
 | 
					        filepath = settings.MEDIA_ROOT / self.subdir / kwargs["path"]
 | 
				
			||||||
 | 
					        return HttpResponse(headers={
 | 
				
			||||||
 | 
					            "Content-Type": "application/force-download",
 | 
				
			||||||
 | 
					            "Content-Disposition": f'attachment; filename="{filepath.name}"',
 | 
				
			||||||
 | 
					            "X-Sendfile": str(filepath).encode("utf-8"),
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PresentationView(TemplateView):
 | 
					class PresentationView(TemplateView):
 | 
				
			||||||
    template_name="presentation.html"
 | 
					    template_name="presentation.html"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,4 +27,6 @@ urlpatterns = [
 | 
				
			||||||
    path("membres/chants/<int:pk>/edit/", views.ChantEditView.as_view(), name="chant-edit"),
 | 
					    path("membres/chants/<int:pk>/edit/", views.ChantEditView.as_view(), name="chant-edit"),
 | 
				
			||||||
    path("membres/chants/<int:pk>/delete/", views.ChantDeleteView.as_view(), name="chant-delete"),
 | 
					    path("membres/chants/<int:pk>/delete/", views.ChantDeleteView.as_view(), name="chant-delete"),
 | 
				
			||||||
    path("membres/documents/", views.MediaView.as_view(prive=True), name="docs-membres"),
 | 
					    path("membres/documents/", views.MediaView.as_view(prive=True), name="docs-membres"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    path("media/chants/<path:path>", views.MediaServeView.as_view(subdir="chants")),
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue