Unverified Commit 5044b804 authored by Diederik van der Boor's avatar Diederik van der Boor
Browse files

Allow overriding the 404 page for missing files

parent d93d2ef1
...@@ -67,9 +67,23 @@ class PrivateStorageView(View): ...@@ -67,9 +67,23 @@ class PrivateStorageView(View):
return HttpResponseForbidden('Private storage access denied') return HttpResponseForbidden('Private storage access denied')
if not private_file.exists(): if not private_file.exists():
raise Http404("File not found") return self.serve_file_not_found(private_file)
else:
return self.serve_file(private_file)
def serve_file_not_found(self, private_file):
"""
Display a response message telling that the file is not found.
This can be overwritten to improve the customer experience.
For example
- redirect the user, and show a message.
- render the message in the expected media type (e.g. PNG).
- show a custom 404 page.
return self.serve_file(private_file) :type private_file: :class:`private_storage.models.PrivateFile`
:rtype: django.http.HttpResponse
"""
raise Http404("File not found")
def serve_file(self, private_file): def serve_file(self, private_file):
""" """
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment