|
1 | 1 | from django.conf import settings |
2 | 2 | from django.core.exceptions import PermissionDenied |
3 | 3 | from django.http import ( |
4 | | - FileResponse, |
5 | 4 | Http404, |
6 | 5 | HttpRequest, |
7 | 6 | HttpResponse, |
8 | 7 | HttpResponseRedirect, |
9 | 8 | ) |
10 | 9 | from django.shortcuts import redirect |
| 10 | +from django.templatetags.static import static |
11 | 11 | from django.urls import reverse_lazy |
| 12 | +from django.utils import timezone |
12 | 13 | from django.utils.decorators import method_decorator |
| 14 | +from django.utils.text import slugify |
13 | 15 | from django.views import View |
14 | 16 | from django.views.generic import ( |
15 | 17 | DetailView, |
|
22 | 24 | staff_required, |
23 | 25 | ) |
24 | 26 | from hypha.apply.utils.models import PDFPageSettings |
25 | | -from hypha.apply.utils.pdfs import draw_submission_content, make_pdf |
| 27 | +from hypha.apply.utils.pdfs import render_as_pdf |
26 | 28 | from hypha.apply.utils.views import ( |
27 | 29 | ViewDispatcher, |
28 | 30 | ) |
| 31 | +from hypha.core.models import SystemSettings |
29 | 32 |
|
30 | 33 | from ..models import ( |
31 | 34 | ApplicationSubmission, |
@@ -287,28 +290,40 @@ def should_redirect(cls, request, submission): |
287 | 290 | class SubmissionDetailPDFView(SingleObjectMixin, View): |
288 | 291 | model = ApplicationSubmission |
289 | 292 |
|
| 293 | + def get_slugified_file_name(self, export_type): |
| 294 | + return f"{timezone.localdate().strftime('%Y%m%d')}-{slugify(self.object.title)}.{export_type}" |
| 295 | + |
290 | 296 | def get(self, request, *args, **kwargs): |
291 | 297 | self.object = self.get_object() |
292 | 298 | pdf_page_settings = PDFPageSettings.load(request_or_site=request) |
293 | | - content = draw_submission_content(self.object.output_text_answers()) |
294 | | - pdf = make_pdf( |
295 | | - title=self.object.title, |
296 | | - sections=[ |
297 | | - { |
298 | | - "content": content, |
299 | | - "title": "Submission", |
300 | | - "meta": [ |
301 | | - self.object.stage, |
302 | | - self.object.page, |
303 | | - self.object.round, |
304 | | - f"Lead: {self.object.lead}", |
305 | | - ], |
306 | | - }, |
307 | | - ], |
308 | | - pagesize=pdf_page_settings.download_page_size, |
| 299 | + context = {} |
| 300 | + context["pagesize"] = pdf_page_settings.download_page_size |
| 301 | + context["show_footer"] = True |
| 302 | + site_settings = SystemSettings.objects.first() |
| 303 | + if site_settings: |
| 304 | + if site_settings.site_logo_default: |
| 305 | + context["logo"] = request.build_absolute_uri( |
| 306 | + site_settings.site_logo_default.file.url |
| 307 | + ) |
| 308 | + else: |
| 309 | + context["logo"] = request.build_absolute_uri(static("images/logo.png")) |
| 310 | + |
| 311 | + context["link"] = self.request.build_absolute_uri( |
| 312 | + self.object.get_absolute_url() |
309 | 313 | ) |
310 | | - return FileResponse( |
311 | | - pdf, |
312 | | - as_attachment=True, |
313 | | - filename=self.object.title + ".pdf", |
| 314 | + context["id"] = self.object.application_id |
| 315 | + context["data"] = self.object.get_text_questions_answers_as_dict() |
| 316 | + context["title"] = self.object.title |
| 317 | + context["stage"] = self.object.stage |
| 318 | + context["fund"] = self.object.page |
| 319 | + context["round"] = self.object.round |
| 320 | + context["lead"] = self.object.lead |
| 321 | + context["show_header"] = True |
| 322 | + context["header_title"] = "Submission details" |
| 323 | + template_path = "funds/submission-pdf.html" |
| 324 | + return render_as_pdf( |
| 325 | + request=request, |
| 326 | + template_name=template_path, |
| 327 | + context=context, |
| 328 | + filename=self.get_slugified_file_name("pdf"), |
314 | 329 | ) |
0 commit comments