Commit eccefb19 authored by Anton Akhmerov's avatar Anton Akhmerov

Merge branch '293-give-attached-pdf-a-distinguishable-name' into 'master'

Resolve "Give attached PDF a distinguishable name"

Closes #293

See merge request !231
parents c37b46d3 c3a27dfa
Pipeline #26627 passed with stages
in 4 minutes and 22 seconds
......@@ -69,10 +69,13 @@ def build_email(exam_id, student_id, template, attach, from_address, copy_to=Non
message=f'Student #{student_id} has no email address'
exam = Exam.query.get(exam_id)
file_name = f"{student_id}_{}.pdf"
render_email(exam_id, student_id, template),
emails.build_solution_attachment(exam_id, student_id)
emails.build_solution_attachment(exam_id, student_id, file_name)
if attach
else None,
......@@ -80,15 +80,19 @@ def render(exam_id, student_id, template):
return template.render(student=student, results=results)
def build_solution_attachment(exam_id, student_id):
def build_solution_attachment(exam_id, student_id, file_name=None):
solution = solution_pdf(exam_id, student_id)
maintype, subtype = 'application', 'pdf'
pdf = MIMEBase(maintype, subtype)
if file_name is None:
# construct the default filename is non is provided
file_name = f"{student_id}.pdf"
# Set the filename parameter
pdf.add_header('Content-Disposition', 'attachment',
pdf.add_header('Content-Disposition', 'attachment', filename=file_name)
return pdf
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment