def test_taking_correct_number_session(self): offer_year_cal = OfferYearCalendarFactory( academic_calendar=self.academic_calendar, offer_year=self.offer_yr) self.assertEqual( session_exam_calendar.find_deliberation_date( number_session.ONE, offer_year_cal.offer_year), datetime.datetime(self.current_academic_yr.year + 1, 1, 1)) self.assertIsNone( session_exam_calendar.find_deliberation_date( number_session.TWO, offer_year_cal.offer_year))
def test_find_deliberation_date(self): SessionExamCalendarFactory(academic_calendar=self.academic_calendar_4, number_session=number_session.ONE) offer_yr = OfferYearFactory(academic_year=self.current_academic_yr) offer_year_cal = OfferYearCalendarFactory( academic_calendar=self.academic_calendar_4, offer_year=offer_yr) self.assertEqual( session_exam_calendar.find_deliberation_date( number_session.ONE, offer_year_cal.offer_year), datetime.date(self.current_academic_yr.year + 1, 1, 1)) self.assertIsNone( session_exam_calendar.find_deliberation_date( number_session.TWO, offer_year_cal.offer_year))
def test_case_deliberation_date_is_set(self): delibe_date = datetime.datetime(self.current_academic_yr.year+1, 6, 10) offer_year_cal = OfferYearCalendarFactory(academic_calendar=self.academic_calendar, offer_year=self.offer_yr, start_date=delibe_date, end_date=delibe_date) self.assertEqual(session_exam_calendar.find_deliberation_date(number_session.ONE, offer_year_cal.offer_year), delibe_date)
def test_case_deliberation_date_is_not_set(self): global_date = self.academic_calendar.start_date delibe_date = None OfferYearCalendarFactory(academic_calendar=self.academic_calendar, offer_year=self.offer_yr, start_date=delibe_date, end_date=delibe_date) result_delibe_date = session_exam_calendar.find_deliberation_date(number_session.ONE, self.offer_yr) self.assertNotEqual(result_delibe_date, global_date) self.assertIsNone(result_delibe_date)
def test_find_deliberation_date_offer_year_cals(self): SessionExamCalendarFactory(academic_calendar=self.academic_calendar_4, number_session=number_session.ONE) offer_yr = OfferYearFactory(academic_year=self.current_academic_yr) global_date = self.academic_calendar_4.start_date delibe_date = datetime.date(self.current_academic_yr.year + 1, 6, 10) offer_year_cal = OfferYearCalendarFactory( academic_calendar=self.academic_calendar_4, offer_year=offer_yr, start_date=delibe_date, end_date=delibe_date) self.assertEqual( session_exam_calendar.find_deliberation_date( number_session.ONE, offer_yr), delibe_date) offer_year_cal.start_date = offer_year_cal.end_date = None offer_year_cal.save() self.assertEqual( session_exam_calendar.find_deliberation_date( number_session.ONE, offer_yr), global_date)
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 enrollments.append({ "registration_id": student.registration_id, "last_name": student.person.last_name, "first_name": student.person.first_name, "score": _format_score(exam_enrol, learning_unit_yr), "justification": _(exam_enrol.get_justification_final_display()) if exam_enrol.justification_final else '', "deadline": _get_formatted_deadline(date_format, exam_enrol), "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 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 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.find_by_person_label(scores_responsible.person, 'PROFESSIONAL') 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.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