def check_for_category_switch(sender, instance, **kwargs): # pylint: disable=unused-argument """ If the exam switches from proctored to timed, notify the backend """ if instance.id: original = sender.objects.get(pk=instance.id) if original.is_proctored and instance.is_proctored != original.is_proctored: from edx_proctoring.serializers import ProctoredExamJSONSafeSerializer exam = ProctoredExamJSONSafeSerializer(instance).data # from the perspective of the backend, the exam is now inactive. exam['is_active'] = False backend = get_backend_provider(name=exam['backend']) backend.on_exam_saved(exam)
def save_exam_on_backend(sender, instance, **kwargs): # pylint: disable=unused-argument """ Save the exam to the backend provider when our model changes. It also combines the review policy into the exam when saving to the backend """ if sender == models.ProctoredExam: exam_obj = instance review_policy = models.ProctoredExamReviewPolicy.get_review_policy_for_exam(instance.id) else: exam_obj = instance.proctored_exam review_policy = instance if exam_obj.is_proctored: from edx_proctoring.serializers import ProctoredExamJSONSafeSerializer exam = ProctoredExamJSONSafeSerializer(exam_obj).data if review_policy: exam['rule_summary'] = review_policy.review_policy backend = get_backend_provider(exam) external_id = backend.on_exam_saved(exam) if external_id and external_id != exam_obj.external_id: exam_obj.external_id = external_id exam_obj.save()