Download evidence from evidence details
This commit is contained in:
parent
aa2b8a750d
commit
435e18c8b6
|
@ -16,6 +16,9 @@
|
|||
</li>
|
||||
<li class="nav-items">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tag">Tag</button>
|
||||
<li class="nav-items">
|
||||
<a href="{% url 'evidence:download' object.uuid %}" class="nav-link">Download File</a>
|
||||
</li>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -17,4 +17,5 @@ urlpatterns = [
|
|||
path("", views.ListEvidencesView.as_view(), name="list"),
|
||||
path("upload", views.UploadView.as_view(), name="upload"),
|
||||
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
||||
path("<uuid:pk>/download", views.DownloadEvidenceView.as_view(), name="download"),
|
||||
]
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import json
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.urls import reverse_lazy
|
||||
|
@ -94,3 +97,18 @@ class EvidenceView(DashboardView, FormView):
|
|||
def get_success_url(self):
|
||||
success_url = reverse_lazy('evidence:details', args=[self.pk])
|
||||
return success_url
|
||||
|
||||
|
||||
class DownloadEvidenceView(DashboardView, TemplateView):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
pk = kwargs['pk']
|
||||
evidence = Evidence(pk)
|
||||
if evidence.owner != self.request.user:
|
||||
raise Http403()
|
||||
|
||||
evidence.get_doc()
|
||||
data = json.dumps(evidence.doc)
|
||||
response = HttpResponse(data, content_type="application/json")
|
||||
response['Content-Disposition'] = 'attachment; filename={}'.format("credential.json")
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue