diff --git a/proposals/utils/pdf_diff_sections.py b/proposals/utils/pdf_diff_sections.py index f4173562..54f21654 100644 --- a/proposals/utils/pdf_diff_sections.py +++ b/proposals/utils/pdf_diff_sections.py @@ -21,6 +21,7 @@ get_extra_documents, multi_sections, KindRow, + AttachmentRow, UploadDateRow, ) @@ -576,8 +577,12 @@ def __init__(self, obj, sub_title, proposal): def make_row_for_field(self, field): + # "kind" and "upload" require slots as their obj, other fields receive + # the attachment as their obj. if field == "kind": return KindRow(self.obj, self.obj.attachment, field) + if field == "upload": + return AttachmentRow(self.obj, field, self.proposal) else: obj = self.obj.attachment diff --git a/proposals/utils/pdf_diff_utils.py b/proposals/utils/pdf_diff_utils.py index 3311f8c2..fe9042ed 100644 --- a/proposals/utils/pdf_diff_utils.py +++ b/proposals/utils/pdf_diff_utils.py @@ -231,6 +231,35 @@ def value(self): return self.slot.kind.name +class AttachmentRow(Row): + """ + This row receives a slot as self.obj and also is basically fully custom. + """ + + def get_verbose_name(self, field): + return _("Bestand") + + def value(self): + + if self.obj.attachment.upload: + output = format_html( + '{}', + settings.BASE_URL + + reverse( + "proposals:download_attachment", + kwargs={ + "proposal_pk": self.proposal.pk, + "attachment_pk": self.obj.attachment.pk, + }, + ), + self.obj.get_fetc_filename(), + ) + else: + output = _("Niet aangeleverd") + + return output + + class UploadDateRow: """ Another very specific row case for attachments. This one just needed to be @@ -280,8 +309,6 @@ def get_field_value(self): return self.handle_user(value) elif isinstance(value, Relation) or isinstance(value, Compensation): return value.description - if value.__class__.__name__ == "FileWrapper": - return self.handle_attachment(value) elif value.__class__.__name__ == "ManyRelatedManager": if value.all().model == User: return self.get_applicants_names(value) @@ -316,26 +343,6 @@ def handle_field_file(self, field_file): return output - def handle_attachment(self, filewrapper): - - if filewrapper: - output = format_html( - '{}', - settings.BASE_URL - + reverse( - "proposals:download_attachment", - kwargs={ - "proposal_pk": self.proposal.pk, - "attachment_pk": self.obj.pk, - }, - ), - _("Download"), - ) - else: - output = _("Niet aangeleverd") - - return output - def yes_no_doubt(self, value): from main.models import YesNoDoubt