Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Added the flag to set a custom body of the email #322

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
39 changes: 25 additions & 14 deletions examtool/examtool/cli/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
help="The email subject to use.",
show_default=True,
)
@click.option(
"--body",
default=None,
help="A file to the body of the email you want sent. You can specify the course by adding `{course}` and the exam name by adding `{exam}`.",
type=click.File("r"),
)
@click.option(
"--filename",
default="Encrypted {course} Exam.pdf",
Expand All @@ -30,7 +36,7 @@
default=False,
help="Use the 61A Mailtool, instead of sendgrid",
)
def send(exam, target, email, subject, filename, mailtool=False):
def send(exam, target, email, subject, body, filename, mailtool=False):
"""
Email an encrypted PDF to all students taking an exam. Specify `email` to email only a particular student.
"""
Expand All @@ -41,19 +47,24 @@ def send(exam, target, email, subject, filename, mailtool=False):

filename = filename.format(course=course)
subject = subject.format(course=course)
body = (
"Hello!\n\n"
"You have an upcoming exam taking place on exam.cs61a.org. "
"You should complete your exam on that website.\n\n"
"Course: {course}\n"
"Exam: {exam}\n\n"
"However, if you encounter technical difficulties and are unable to do so, "
"we have attached an encrypted PDF containing the same exam. "
"You can then email your exam solutions to course staff before the deadline "
"rather than submitting using exam.cs61a.org. "
"To unlock the PDF, use the password that is revealed on Piazza when the exam starts.\n\n"
"Good luck, and remember to have fun!"
).format(course=course, exam=exam)
if body is None:
body = (
"Hello!\n\n"
"You have an upcoming exam taking place on exam.cs61a.org. "
"You should complete your exam on that website.\n\n"
"Course: {course}\n"
"Exam: {exam}\n\n"
"However, if you encounter technical difficulties and are unable to do so, "
"we have attached an encrypted PDF containing the same exam. "
"You can then email your exam solutions to course staff before the deadline "
"rather than submitting using exam.cs61a.org. "
"To unlock the PDF, use the password that is revealed on Piazza when the exam starts.\n\n"
"Good luck, and remember to have fun!"
)
else:
body = body.read()

body = body.format(course=course, exam=exam)

roster = []
if email:
Expand Down