Skip to content

Commit

Permalink
Feat/fetc filename in pdf (#837)
Browse files Browse the repository at this point in the history
* feat: create custom attachment row

* feat: make us of the custom attachment row

* style: black
  • Loading branch information
EdoStorm96 authored Jan 8, 2025
1 parent 70f7421 commit eef2eae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
5 changes: 5 additions & 0 deletions proposals/utils/pdf_diff_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
get_extra_documents,
multi_sections,
KindRow,
AttachmentRow,
UploadDateRow,
)

Expand Down Expand Up @@ -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

Expand Down
51 changes: 29 additions & 22 deletions proposals/utils/pdf_diff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<a href="{}">{}</a>',
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -316,26 +343,6 @@ def handle_field_file(self, field_file):

return output

def handle_attachment(self, filewrapper):

if filewrapper:
output = format_html(
'<a href="{}">{}</a>',
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

Expand Down

0 comments on commit eef2eae

Please sign in to comment.