def online_encoding_submission(request, session_id): session_exam = SessionExam.find_session(session_id) enrollments = ExamEnrollment.find_draft_exam_enrollments(session_exam) all_encoded = True for enrollment in enrollments: if enrollment.score_draft or enrollment.justification_draft: if enrollment.score_draft: enrollment.score_final = enrollment.score_draft if enrollment.justification_draft: enrollment.justification_final = enrollment.justification_draft enrollment.save() ExamEnrollmentHistory.exam_enrollment_historic(request.user,enrollment,enrollment.score_final,enrollment.justification_final) else: all_encoded = False if all_encoded: session_exam.status = 'CLOSED' session_exam.save() #Send mail to all the teachers of the submitted learning unit on any submission learning_unit = session_exam.learning_unit_year.learning_unit attributions = Attribution.objects.filter(learning_unit=learning_unit) persons = [attribution.tutor.person for attribution in attributions if attribution.function == 'PROFESSOR'] send_mail.send_mail_after_scores_submission(persons,learning_unit.acronym) return HttpResponseRedirect(reverse('online_encoding', args=(session_id,)))
def online_encoding_submission(request, learning_unit_year_id): scores_list = score_encoding_list.get_scores_encoding_list(user=request.user, learning_unit_year_id=learning_unit_year_id) submitted_enrollments = [] draft_scores_not_sumitted_yet = scores_list.enrollment_draft_not_submitted not_submitted_enrollments = set([ex for ex in scores_list.enrollments if not ex.is_final]) for exam_enroll in draft_scores_not_sumitted_yet: if (exam_enroll.score_draft is not None and exam_enroll.score_final is None) \ or (exam_enroll.justification_draft and not exam_enroll.justification_final): submitted_enrollments.append(exam_enroll) not_submitted_enrollments.remove(exam_enroll) if exam_enroll.is_draft: if exam_enroll.score_draft is not None: exam_enroll.score_final = exam_enroll.score_draft if exam_enroll.justification_draft: exam_enroll.justification_final = exam_enroll.justification_draft exam_enroll.full_clean() with transaction.atomic(): exam_enroll.save() mdl.exam_enrollment.create_exam_enrollment_historic(request.user, exam_enroll) # Send mail to all the teachers of the submitted learning unit on any submission all_encoded = len(not_submitted_enrollments) == 0 learning_unit_year = mdl.learning_unit_year.get_by_id(learning_unit_year_id) attributions = mdl_attr.attribution.Attribution.objects.filter(learning_unit_year=learning_unit_year) persons = list(set([attribution.tutor.person for attribution in attributions])) send_mail.send_mail_after_scores_submission(persons, learning_unit_year.acronym, submitted_enrollments, all_encoded) return HttpResponseRedirect(reverse('online_encoding', args=(learning_unit_year_id,)))