def _get_formatted_deadline(date_format, exam_enrol): # Compute deadline score encoding if exam_enrol.enrollment_state == enrollment_states.ENROLLED: deadline = get_deadline(exam_enrol) if deadline: return deadline.strftime(date_format) return ''
def _append_session_exam_deadline(enrollments): for enrollment in enrollments: enrollment.deadline = exam_enrollment.get_deadline(enrollment) enrollment.deadline_reached = exam_enrollment.is_deadline_reached( enrollment) enrollment.deadline_tutor_reached = exam_enrollment.is_deadline_tutor_reached( enrollment) return enrollments
def scores_sheet_data(exam_enrollments, tutor=None): date_format = str(_('date_format')) exam_enrollments = sort_encodings(exam_enrollments) data = {'tutor_global_id': tutor.person.global_id if tutor else ''} now = timezone.now() data['publication_date'] = '%s/%s/%s' % (now.day, now.month, now.year) data['institution'] = str(_('ucl_denom_location')) data['link_to_regulation'] = str(_('link_to_RGEE')) data['justification_legend'] = _('justification_legend') % justification_label_authorized() # Will contain lists of examEnrollments splitted by learningUnitYear enrollments_by_learn_unit = _group_by_learning_unit_year_id( exam_enrollments) # {<learning_unit_year_id> : [<ExamEnrollment>]} learning_unit_years = [] for exam_enrollments in enrollments_by_learn_unit.values(): # exam_enrollments contains all ExamEnrollment for a learningUnitYear learn_unit_year_dict = {} # We can take the first element of the list 'exam_enrollments' to get the learning_unit_yr # because all exam_enrollments have the same learningUnitYear learning_unit_yr = exam_enrollments[0].session_exam.learning_unit_year scores_responsible = attribution.find_responsible(learning_unit_yr.id) scores_responsible_address = None person = None if scores_responsible: person = scores_responsible.person scores_responsible_address = person_address.get_by_label(scores_responsible.person, PersonAddressType.PROFESSIONAL.value) learn_unit_year_dict['academic_year'] = str(learning_unit_yr.academic_year) learn_unit_year_dict['scores_responsible'] = { 'first_name': person.first_name if person and person.first_name else '', 'last_name': person.last_name if person and person.last_name else ''} learn_unit_year_dict['scores_responsible']['address'] = {'location': scores_responsible_address.location if scores_responsible_address else '', 'postal_code': scores_responsible_address.postal_code if scores_responsible_address else '', 'city': scores_responsible_address.city if scores_responsible_address else ''} learn_unit_year_dict['session_number'] = exam_enrollments[0].session_exam.number_session learn_unit_year_dict['acronym'] = learning_unit_yr.acronym learn_unit_year_dict['title'] = learning_unit_yr.specific_title learn_unit_year_dict['decimal_scores'] = learning_unit_yr.decimal_scores programs = [] # Will contain lists of examEnrollments by offerYear (=Program) enrollments_by_program = {} # {<offer_year_id> : [<ExamEnrollment>]} for exam_enroll in exam_enrollments: key = exam_enroll.learning_unit_enrollment.offer_enrollment.offer_year.id if key not in enrollments_by_program.keys(): enrollments_by_program[key] = [exam_enroll] else: enrollments_by_program[key].append(exam_enroll) for list_enrollments in enrollments_by_program.values(): # exam_enrollments by OfferYear exam_enrollment = list_enrollments[0] off_year = exam_enrollment.learning_unit_enrollment.offer_enrollment.offer_year number_session = exam_enrollment.session_exam.number_session deliberation_date = session_exam_calendar.find_deliberation_date(number_session, off_year) if deliberation_date: deliberation_date = deliberation_date.strftime(date_format) else: deliberation_date = _('not_passed') program = {'acronym': exam_enrollment.learning_unit_enrollment.offer_enrollment.offer_year.acronym, 'deliberation_date': deliberation_date, 'address': _get_serialized_address(off_year)} enrollments = [] for exam_enrol in list_enrollments: student = exam_enrol.learning_unit_enrollment.student score = '' if exam_enrol.score_final is not None: if learning_unit_yr.decimal_scores: score = str(exam_enrol.score_final) else: score = str(int(exam_enrol.score_final)) # Compute deadline score encoding deadline = get_deadline(exam_enrol) if deadline: deadline = deadline.strftime(date_format) enrollments.append({ "registration_id": student.registration_id, "last_name": student.person.last_name, "first_name": student.person.first_name, "score": score, "justification": _(exam_enrol.justification_final) if exam_enrol.justification_final else '', "deadline": deadline if deadline else '' }) program['enrollments'] = enrollments programs.append(program) programs = sorted(programs, key=lambda k: k['acronym']) learn_unit_year_dict['programs'] = programs learning_unit_years.append(learn_unit_year_dict) learning_unit_years = sorted(learning_unit_years, key=lambda k: k['acronym']) data['learning_unit_years'] = learning_unit_years return data
def scores_sheet_data(exam_enrollments, tutor=None): date_format = str(_('date_format')) exam_enrollments = sort_encodings(exam_enrollments) data = {'tutor_global_id': tutor.person.global_id if tutor else ''} now = timezone.now() data['publication_date'] = '%s/%s/%s' % (now.day, now.month, now.year) data['institution'] = 'Université catholique de Louvain' data['link_to_regulation'] = 'https://www.uclouvain.be/enseignement-reglements.html' data['justification_legend'] = \ _('Justification legend: %(justification_label_authorized)s') % \ {'justification_label_authorized': justification_label_authorized()} # Will contain lists of examEnrollments splitted by learningUnitYear enrollments_by_learn_unit = _group_by_learning_unit_year_id( exam_enrollments) # {<learning_unit_year_id> : [<ExamEnrollment>]} learning_unit_years = [] for exam_enrollments in enrollments_by_learn_unit.values(): # exam_enrollments contains all ExamEnrollment for a learningUnitYear learn_unit_year_dict = {} # We can take the first element of the list 'exam_enrollments' to get the learning_unit_yr # because all exam_enrollments have the same learningUnitYear learning_unit_yr = exam_enrollments[0].session_exam.learning_unit_year scores_responsible = attribution.find_responsible(learning_unit_yr.id) scores_responsible_address = None person = None if scores_responsible: person = scores_responsible.person scores_responsible_address = person_address.get_by_label(scores_responsible.person, PersonAddressType.PROFESSIONAL.value) learn_unit_year_dict['academic_year'] = str(learning_unit_yr.academic_year) learn_unit_year_dict['scores_responsible'] = { 'first_name': person.first_name if person and person.first_name else '', 'last_name': person.last_name if person and person.last_name else ''} learn_unit_year_dict['scores_responsible']['address'] = {'location': scores_responsible_address.location if scores_responsible_address else '', 'postal_code': scores_responsible_address.postal_code if scores_responsible_address else '', 'city': scores_responsible_address.city if scores_responsible_address else ''} learn_unit_year_dict['session_number'] = exam_enrollments[0].session_exam.number_session learn_unit_year_dict['acronym'] = learning_unit_yr.acronym learn_unit_year_dict['title'] = learning_unit_yr.complete_title learn_unit_year_dict['decimal_scores'] = learning_unit_yr.decimal_scores programs = [] # Will contain lists of examEnrollments by offerYear (=Program) enrollments_by_program = {} # {<offer_year_id> : [<ExamEnrollment>]} for exam_enroll in exam_enrollments: key = exam_enroll.learning_unit_enrollment.offer_enrollment.offer_year.id if key not in enrollments_by_program.keys(): enrollments_by_program[key] = [exam_enroll] else: enrollments_by_program[key].append(exam_enroll) for list_enrollments in enrollments_by_program.values(): # exam_enrollments by OfferYear exam_enrollment = list_enrollments[0] off_year = exam_enrollment.learning_unit_enrollment.offer_enrollment.offer_year number_session = exam_enrollment.session_exam.number_session deliberation_date = session_exam_calendar.find_deliberation_date(number_session, off_year) if deliberation_date: deliberation_date = deliberation_date.strftime(date_format) else: deliberation_date = _('Not passed') program = {'acronym': exam_enrollment.learning_unit_enrollment.offer_enrollment.offer_year.acronym, 'deliberation_date': deliberation_date, 'address': _get_serialized_address(off_year)} enrollments = [] for exam_enrol in list_enrollments: student = exam_enrol.learning_unit_enrollment.student score = '' if exam_enrol.score_final is not None: if learning_unit_yr.decimal_scores: score = str(exam_enrol.score_final) else: score = str(int(exam_enrol.score_final)) # Compute deadline score encoding deadline = get_deadline(exam_enrol) if deadline: deadline = deadline.strftime(date_format) enrollments.append({ "registration_id": student.registration_id, "last_name": student.person.last_name, "first_name": student.person.first_name, "score": score, "justification": _(exam_enrol.get_justification_final_display()) if exam_enrol.justification_final else '', "deadline": deadline if deadline else '', "enrollment_state_color": get_line_color(exam_enrol), }) program['enrollments'] = enrollments programs.append(program) programs = sorted(programs, key=lambda k: k['acronym']) learn_unit_year_dict['programs'] = programs learning_unit_years.append(learn_unit_year_dict) learning_unit_years = sorted(learning_unit_years, key=lambda k: k['acronym']) data['learning_unit_years'] = learning_unit_years return data
def _append_session_exam_deadline(enrollments): for enrollment in enrollments: enrollment.deadline = exam_enrollment.get_deadline(enrollment) enrollment.deadline_reached = exam_enrollment.is_deadline_reached(enrollment) enrollment.deadline_tutor_reached = exam_enrollment.is_deadline_tutor_reached(enrollment) return enrollments