handler:get: only add comment to submission response if it exists.
authorW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 14:55:42 +0000 (10:55 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 14:55:42 +0000 (10:55 -0400)
This avoids potentially confusing responses like:

> Assignment 1 grade: 8.0
>
> None

pygrader/handler/get.py

index e354d2ad1d9700971ebf2e8edabab15458ad861e..24d79c4e3182a10242a499463619c98a2397b57f 100644 (file)
@@ -419,9 +419,10 @@ def _get_student_submission_email(
     for assignment in assignments:
         grade = course.grade(student=student, assignment=assignment)
         if grade is not None:
-            message.attach(_pgp_mime.encodedMIMEText(
-                    '{} grade: {}\n\n{}\n'.format(
-                        assignment.name, grade.points, grade.comment)))
+            text = '{} grade: {}\n'.format(assignment.name, grade.points)
+            if grade.comment:
+                text += '\n{}\n'.format(grade.comment)
+            message.attach(_pgp_mime.encodedMIMEText(text))
         assignment_path = _assignment_path(basedir, assignment, student)
         mpath = _os_path.join(assignment_path, 'mail')
         try: