Commit 57b9f09127e84051109cdcf3557ad6d069f5121f

Authored by Zambom
1 parent 29a31a64

Adding file path inexist handler

Showing 1 changed file with 4 additions and 1 deletions   Show diff stats
file_link/views.py
1 from django.shortcuts import get_object_or_404, redirect, render 1 from django.shortcuts import get_object_or_404, redirect, render
2 -from django.http import HttpResponse 2 +from django.http import HttpResponse, Http404
3 from os import path 3 from os import path
4 from django.views import generic 4 from django.views import generic
5 from django.contrib import messages 5 from django.contrib import messages
@@ -35,6 +35,9 @@ class DownloadFile(LoginRequiredMixin, generic.DetailView): @@ -35,6 +35,9 @@ class DownloadFile(LoginRequiredMixin, generic.DetailView):
35 slug = self.kwargs.get('slug', '') 35 slug = self.kwargs.get('slug', '')
36 file_link = get_object_or_404(FileLink, slug = slug) 36 file_link = get_object_or_404(FileLink, slug = slug)
37 37
  38 + if not path.exists(file_link.file_content.path):
  39 + raise Http404()
  40 +
38 response = HttpResponse(open(file_link.file_content.path, 'rb').read()) 41 response = HttpResponse(open(file_link.file_content.path, 'rb').read())
39 response['Content-Type'] = 'application/force-download' 42 response['Content-Type'] = 'application/force-download'
40 response['Pragma'] = 'public' 43 response['Pragma'] = 'public'