Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/fetc filename in pdf #837

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading