本文整理汇总了Python中notification.models.Notification.send方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.send方法的具体用法?Python Notification.send怎么用?Python Notification.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notification.models.Notification
的用法示例。
在下文中一共展示了Notification.send方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_notification_send
# 需要导入模块: from notification.models import Notification [as 别名]
# 或者: from notification.models.Notification import send [as 别名]
def test_notification_send(self):
notifications = Notification.objects.all()
self.assertEqual(1, len(notifications))
self.assertEqual(self.student.userprofile, notifications[0].sender)
self.assertEqual(self.teacher.userprofile, notifications[0].recipient)
self.assertEqual(self.course_instance, notifications[0].course_instance)
self.assertEqual("testSubject", notifications[0].subject)
self.assertEqual("testNotification", notifications[0].notification)
self.assertFalse(notifications[0].seen)
Notification.send(self.teacher.userprofile, self.student.userprofile, self.course_instance, "subject", "notification")
notifications = Notification.objects.all()
self.assertEqual(2, len(notifications))
self.assertEqual(self.teacher.userprofile, notifications[0].sender)
self.assertEqual(self.student.userprofile, notifications[0].recipient)
self.assertEqual(self.course_instance, notifications[0].course_instance)
self.assertEqual("subject", notifications[0].subject)
self.assertEqual("notification", notifications[0].notification)
self.assertFalse(notifications[0].seen)
self.assertEqual(self.student.userprofile, notifications[1].sender)
self.assertEqual(self.teacher.userprofile, notifications[1].recipient)
self.assertEqual(self.course_instance, notifications[1].course_instance)
self.assertEqual("testSubject", notifications[1].subject)
self.assertEqual("testNotification", notifications[1].notification)
self.assertFalse(notifications[1].seen)
示例2: form_valid
# 需要导入模块: from notification.models import Notification [as 别名]
# 或者: from notification.models.Notification import send [as 别名]
def form_valid(self, form):
assistant_feedback = form.cleaned_data["assistant_feedback"]
feedback = form.cleaned_data["feedback"]
note = ""
if self.submission.assistant_feedback != assistant_feedback:
note = assistant_feedback
elif self.submission.feedback != feedback:
note = feedback
self.submission.set_points(form.cleaned_data["points"],
self.exercise.max_points, no_penalties=True)
self.submission.grader = self.profile
self.submission.assistant_feedback = assistant_feedback
self.submission.feedback = feedback
self.submission.set_ready()
self.submission.save()
sub = _('Feedback to {name}').format(name=self.exercise)
msg = _('<p>You have new personal feedback to exercise '
'<a href="{url}">{name}</a>.</p>{message}').format(
url=self.submission.get_absolute_url(),
name=self.exercise,
message=note,
)
for student in self.submission.submitters.all():
Notification.send(self.profile, student, self.instance, sub, msg)
messages.success(self.request, _("The review was saved successfully "
"and the submitters were notified."))
return super().form_valid(form)
示例3: _post_async_submission
# 需要导入模块: from notification.models import Notification [as 别名]
# 或者: from notification.models.Notification import send [as 别名]
def _post_async_submission(request, exercise, submission, errors=None):
"""
Creates or grades a submission.
Required parameters in the request are points, max_points and feedback. If
errors occur or submissions are no longer accepted, a dictionary with
"success" is False and "errors" list will be returned.
"""
if not errors:
errors = []
# Use form to parse and validate the request.
form = SubmissionCallbackForm(request.POST)
errors.extend(extract_form_errors(form))
if not form.is_valid():
submission.feedback = _(
"<div class=\"alert alert-error\">\n"
"<p>The exercise assessment service is malfunctioning. "
"Staff has been notified.</p>\n"
"<p>This submission is now marked as erroneous.</p>\n"
"</div>")
submission.set_error()
submission.save()
if exercise.course_instance.visible_to_students:
msg = "Exercise service returned with invalid grade request: {}"\
.format("\n".join(errors))
logger.error(msg, extra={"request": request})
email_course_error(request, exercise, msg, False)
return {
"success": False,
"errors": errors
}
# Grade the submission.
try:
submission.set_points(form.cleaned_data["points"],
form.cleaned_data["max_points"])
submission.feedback = form.cleaned_data["feedback"]
submission.grading_data = request.POST
if form.cleaned_data["error"]:
submission.set_error()
else:
submission.set_ready()
submission.save()
if form.cleaned_data["notify"]:
Notification.send(None, submission)
else:
Notification.remove(submission)
return {
"success": True,
"errors": []
}
# Produce error if something goes wrong during saving the points.
except Exception as e:
logger.exception("Unexpected error while saving grade"
" for {} and submission id {:d}".format(str(exercise), submission.id));
return {
"success": False,
"errors": [repr(e)]
}
示例4: assess_submission
# 需要导入模块: from notification.models import Notification [as 别名]
# 或者: from notification.models.Notification import send [as 别名]
def assess_submission(request, submission_id):
"""
This view is used for assessing the given exercise submission. When
assessing, the teacher or assistant may write verbal feedback and give a
numeric grade for the submission. Changing the grade or writing feedback
will send a notification to the submitters.
Late submission penalty is not applied to the grade.
@param submission_id: the ID of the submission to assess
"""
submission = get_object_or_404(Submission, id=submission_id)
exercise = submission.exercise
grader = request.user.get_profile()
if exercise.allow_assistant_grading:
# Both the teachers and assistants are allowed to assess
has_permission = exercise.get_course_instance().is_staff(grader)
else:
# Only teacher is allowed to assess
has_permission = exercise.get_course_instance().is_teacher(
request.user.get_profile())
if not has_permission:
return HttpResponseForbidden(_("You are not allowed to access this "
"view."))
form = SubmissionReviewForm(exercise=exercise, initial={"points": submission.grade,
"feedback": submission.feedback,
"assistant_feedback": submission.assistant_feedback})
if request.method == "POST":
form = SubmissionReviewForm(request.POST, exercise=exercise)
if form.is_valid():
submission.set_points(form.cleaned_data["points"],
exercise.max_points, no_penalties=True)
submission.grader = grader
submission.assistant_feedback = form.cleaned_data["assistant_feedback"]
submission.feedback = form.cleaned_data["feedback"]
submission.set_ready()
submission.save()
breadcrumb = exercise.get_breadcrumb()
for student in submission.submitters.all():
Notification.send(grader,
student,
exercise.get_course_instance(),
'New assistant feedback',
'<p>You have new assistant feedback to exercise <a href="'\
+ breadcrumb[2][1]+'">' + exercise.name +'</a>:</p>'\
+ submission.assistant_feedback)
messages.success(request, _("The review was saved "
"successfully."))
return redirect(inspect_exercise_submission,
submission_id=submission.id)
return render_to_response("exercise/submission_assessment.html",
CourseContext(request,
course_instance=exercise
.get_course_instance(),
exercise=exercise,
submission=submission,
form=form))