Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
from django.template.loader import render_to_string
from django.urls import reverse
message = render_to_string("course/grade-internal-notes-notify.txt", {
"page_title": self.title(page_context, page_data),
"course": page_context.course,
"participation": page_context.flow_session.participation,
"notes_text": grade_data["notes"],
"flow_session": page_context.flow_session,
"review_uri": page_context.page_uri,
"sender": request.user
})
from django.core.mail import EmailMessage
msg = EmailMessage(
string_concat("[%(identifier)s:%(flow_id)s] ",
_("Grading notes from %(ta)s"))
% {'identifier': page_context.course.identifier,
'flow_id': page_context.flow_session.flow_id,
'ta': request.user.get_full_name()
},
message,
getattr(settings, "GRADER_FEEDBACK_EMAIL_FROM",
page_context.course.get_from_email()),
[page_context.course.notify_email])
msg.bcc = [request.user.email]
msg.reply_to = [request.user.email]
if hasattr(settings, "GRADER_FEEDBACK_EMAIL_FROM"):
from relate.utils import get_outbound_mail_connection
msg.connection = get_outbound_mail_connection("grader_feedback")
return grade_data
def grading_form_to_html(self, request, page_context, grading_form, grade_data):
ctx = {
"form": grading_form,
"rubric": markup_to_html(page_context, self.page_desc.rubric)
}
from django.template.loader import render_to_string
return render_to_string(
Dong Zhuang
committed
"course/human-feedback-form.html", ctx, request)
def grade(
self,
page_context, # type: PageContext
page_data, # type: Any
answer_data, # type: Any
grade_data, # type: Any
):
# type: (...) -> Optional[AnswerFeedback]
"""This method is appropriate if the grade consists *only* of the
feedback provided by humans. If more complicated/combined feedback
is desired, a subclass would likely override this.
"""
if answer_data is None:
return AnswerFeedback(correctness=0,
if grade_data is None:
return None
if not grade_data["released"]:
return None
if (grade_data["grade_percent"] is not None
or grade_data["feedback_text"]):
if grade_data["grade_percent"] is not None:
correctness = grade_data["grade_percent"]/100
feedback_text = "<p>%s</p>" % get_auto_feedback(correctness)
else:
correctness = None
feedback_text = ""
if grade_data["feedback_text"]:
feedback_text += (
string_concat(
"<p>",
_("The following feedback was provided"),
":<p>")
+ markup_to_html(
page_context, grade_data["feedback_text"],
use_jinja=False))
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
return AnswerFeedback(
correctness=correctness,
feedback=feedback_text)
else:
return None
class PageBaseWithCorrectAnswer(PageBase):
def allowed_attrs(self):
return super(PageBaseWithCorrectAnswer, self).allowed_attrs() + (
("correct_answer", "markup"),
)
def correct_answer(self, page_context, page_data, answer_data, grade_data):
if hasattr(self.page_desc, "correct_answer"):
return markup_to_html(page_context, self.page_desc.correct_answer)
else:
return None
# }}}
def get_editor_interaction_mode(page_context):
if (page_context.flow_session is not None
and page_context.flow_session.participation is not None):
return page_context.flow_session.participation.user.editor_mode
else:
return "default"