diff --git a/hypha/apply/projects/templates/application_projects/project_simplified_detail.html b/hypha/apply/projects/templates/application_projects/project_simplified_detail.html index 40cc585fb66f2dad1f7cc7fb406a96e15130dbd5..675d2228695479c6558592a3b35db070b460ac8c 100644 --- a/hypha/apply/projects/templates/application_projects/project_simplified_detail.html +++ b/hypha/apply/projects/templates/application_projects/project_simplified_detail.html @@ -17,6 +17,12 @@ <span>{{ object.submission.round }}</span> <span>Lead: {{ object.lead }}</span> </h5> + <a + class="button button--primary simplified__button" + href="{% url "apply:projects:download" pk=object.pk %}" + > + Download PDF + </a> </div> </div> diff --git a/hypha/apply/projects/urls.py b/hypha/apply/projects/urls.py index 41d28497532b41fe68ee4e7d142d6ebc1ffb30a1..75b596ba7b5e25f5194e0b2a2f0c6fd2ad628e17 100644 --- a/hypha/apply/projects/urls.py +++ b/hypha/apply/projects/urls.py @@ -12,6 +12,7 @@ from .views import ( ProjectDetailView, ProjectEditView, ProjectListView, + ProjectDetailPDFView, ProjectOverviewView, ProjectPrivateMediaView, ReportDetailView, @@ -31,6 +32,7 @@ urlpatterns = [ path('edit/', ProjectEditView.as_view(), name="edit"), path('documents/<int:file_pk>/', ProjectPrivateMediaView.as_view(), name="document"), path('contract/<int:file_pk>/', ContractPrivateMediaView.as_view(), name="contract"), + path('download/', ProjectDetailPDFView.as_view(), name='download'), path('simplified/', ProjectDetailSimplifiedView.as_view(), name='simplified'), path('request/', CreatePaymentRequestView.as_view(), name='request'), ])), diff --git a/hypha/apply/projects/views/project.py b/hypha/apply/projects/views/project.py index f90774d2f882a253a9442c3383056243d4aca24a..657046a6c59ef412caa335875e687d7ef7e93ae6 100644 --- a/hypha/apply/projects/views/project.py +++ b/hypha/apply/projects/views/project.py @@ -6,7 +6,7 @@ from django.contrib.auth.mixins import UserPassesTestMixin from django.core.exceptions import PermissionDenied from django.db import transaction from django.db.models import Count -from django.http import Http404 +from django.http import FileResponse, Http404 from django.shortcuts import get_object_or_404, redirect from django.urls import reverse, reverse_lazy from django.utils import timezone @@ -14,6 +14,7 @@ from django.utils.decorators import method_decorator from django.utils.functional import cached_property from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ +from django.views import View from django.views.generic import ( CreateView, DetailView, @@ -21,12 +22,14 @@ from django.views.generic import ( TemplateView, UpdateView, ) +from django.views.generic.detail import SingleObjectMixin from django_filters.views import FilterView from django_tables2 import SingleTableMixin from hypha.apply.activity.messaging import MESSAGES, messenger from hypha.apply.activity.views import ActivityContextMixin, CommentFormView from hypha.apply.users.decorators import approver_required, staff_required +from hypha.apply.utils.pdfs import make_pdf from hypha.apply.utils.storage import PrivateMediaView from hypha.apply.utils.views import DelegateableView, DelegatedViewMixin, ViewDispatcher @@ -518,6 +521,29 @@ class ProjectDetailSimplifiedView(DetailView): template_name_suffix = '_simplified_detail' +@method_decorator(staff_required, name='dispatch') +class ProjectDetailPDFView(SingleObjectMixin, View): + model = Project + + def get(self, request, *args, **kwargs): + self.object = self.get_object().submission + pdf = make_pdf( + title=self.object.title, + meta=[ + self.object.stage, + self.object.page, + self.object.round, + f"Lead: { self.object.lead }", + ], + content=self.object.output_text_answers() + ) + return FileResponse( + pdf, + as_attachment=True, + filename=self.object.title + '.pdf', + ) + + class ProjectApprovalEditView(UpdateView): form_class = ProjectApprovalForm model = Project