Commit 8e9d90da authored by Diederik van der Boor's avatar Diederik van der Boor
Browse files

Split PrivateStorageView in more methods for easier reuse.

- Added get_path()
- Added get_private_file()
- no longer depend on `self.kwargs['path`]`.
parent 6899bf24
......@@ -25,18 +25,30 @@ class PrivateStorageView(View):
#: Import the server class once
server_class = get_server_class(appconfig.PRIVATE_STORAGE_SERVER)
def get(self, request, *args, **kwargs):
def get_path(self):
"""
Handle incoming GET requests
Determine the path for the object to provide.
This can be overwritten to combine the view with a different object retrieval.
"""
return self.kwargs['path']
def get_private_file(self):
"""
Return all relevant data in a single object, so this is easy to extend
and server implementations can pick what they need.
"""
# Wrap all relevant data in a single object,
# so this is easy to extend and server implementations can pick what they need.
private_file = PrivateFile(
return PrivateFile(
request=self.request,
storage=self.storage,
relative_name=self.kwargs['path']
relative_name=self.get_path()
)
def get(self, request, *args, **kwargs):
"""
Handle incoming GET requests
"""
private_file = self.get_private_file()
if not self.can_access_file(private_file):
return HttpResponseForbidden('Private storage access denied')
......@@ -48,6 +60,9 @@ class PrivateStorageView(View):
def serve_file(self, private_file):
"""
Serve the file that was retrieved from the storage.
The relative path can be found in ``self.kwargs['path']``.
The relative path can be found with ``private_file.relative_name``.
:type private_file: :class:`private_storage.models.PrivateFile`
:rtype: django.http.HttpResponse
"""
return self.server_class().serve(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