-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDR-1356 Add authenticated consent file download view
* Point the consent form field to a view instead of MEDIA_URL. * Only a user who is logged in can download from the view. * Replaced redundant usage of FileSystemStorage. * There is no authorization based on registry/user level, etc.
- Loading branch information
Rodney Lorrimar
committed
Jul 6, 2016
1 parent
dba06e2
commit 903e19c
Showing
3 changed files
with
55 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from django.conf.urls import * | ||
from django.conf.urls import patterns, url | ||
from django.conf.urls import url | ||
from django.contrib import admin | ||
|
||
from .views import ConsentFileView | ||
|
||
urlpatterns = patterns('', | ||
#(r'^admin/', include(admin.site.urls), {}), | ||
|
||
) | ||
urlpatterns = [ | ||
url("^download/(?P<consent_id>\d+)/(?P<filename>.*)$", | ||
ConsentFileView.as_view(), | ||
name="consent-form-download"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
from django.http import HttpResponse | ||
|
||
import os.path | ||
from django.contrib.auth.decorators import login_required | ||
from django.http import HttpResponse, FileResponse | ||
from django.shortcuts import get_object_or_404 | ||
from django.utils.decorators import method_decorator | ||
from django.views.generic import View | ||
from .models import PatientConsent | ||
|
||
def update_session(request): | ||
key = request.POST["key"] | ||
value = request.POST["value"] | ||
request.session[key] = value | ||
return HttpResponse('ok') | ||
|
||
|
||
class ConsentFileView(View): | ||
@method_decorator(login_required) | ||
def get(self, request, consent_id=None, filename=""): | ||
consent = get_object_or_404(PatientConsent, pk=consent_id) | ||
response = FileResponse(consent.form.file, content_type='application/octet-stream') | ||
response['Content-disposition'] = "filename=%s" % consent.filename | ||
return response |