def learning_units_summary_list(request): a_user_person = find_by_user(request.user) learning_units_found = [] initial_academic_year = current_academic_year() if academic_calendar.is_academic_calendar_has_started(initial_academic_year, SUMMARY_COURSE_SUBMISSION): initial_academic_year = initial_academic_year.next() search_form = LearningUnitYearForm(request.GET or None, initial={'academic_year_id': initial_academic_year}) try: if search_form.is_valid(): learning_units_found_search = search_form.get_learning_units( requirement_entities=a_user_person.find_main_entities_version, luy_status=True ) learning_units_found = get_learning_units_and_summary_status(learning_units_found_search) check_if_display_message(request, learning_units_found_search) except TooManyResultsException: display_error_messages(request, 'too_many_results') responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list(learning_units_found) learning_units = sorted(learning_units_found, key=lambda learning_yr: learning_yr.acronym) errors = [can_learning_unit_year_educational_information_be_udpated(learning_unit_year_id=luy.id) for luy in learning_units] context = { 'form': search_form, 'formset': _get_formset(request, responsible_and_learning_unit_yr_list), 'learning_units_with_errors': list(zip(learning_units, errors)), 'experimental_phase': True, 'search_type': SUMMARY_LIST, 'is_faculty_manager': a_user_person.is_faculty_manager() } return layout.render(request, "learning_units.html", context)
def learning_units_summary_list(request): a_user_person = request.user.person found_learning_units = LearningUnitYear.objects.none() initial_academic_year = current_academic_year() if academic_calendar.is_academic_calendar_has_started( initial_academic_year, SUMMARY_COURSE_SUBMISSION): initial_academic_year = initial_academic_year.next() search_form = LearningUnitYearForm(request.GET or None, initial={ 'academic_year_id': initial_academic_year, 'with_entity_subordinated': True }) try: if search_form.is_valid(): found_learning_units = search_form.get_learning_units_and_summary_status( requirement_entities=a_user_person.find_main_entities_version, ) check_if_display_message(request, found_learning_units) except TooManyResultsException: display_error_messages(request, 'too_many_results') responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list( found_learning_units) for luy in found_learning_units: luy.errors = can_learning_unit_year_educational_information_be_udpated( learning_unit_year_id=luy) if request.GET.get('xls_status') == "xls_teaching_material": try: return generate_xls_teaching_material(request.user, found_learning_units) except ObjectDoesNotExist: display_warning_messages( request, _("the list to generate is empty.").capitalize()) form_comparison = SelectComparisonYears( academic_year=get_academic_year_of_reference(found_learning_units)) context = { 'form': search_form, 'formset': _get_formset(request, responsible_and_learning_unit_yr_list), 'learning_units_count': found_learning_units.count(), 'search_type': SUMMARY_LIST, 'is_faculty_manager': a_user_person.is_faculty_manager, 'form_comparison': form_comparison, 'page_obj': paginate_queryset(found_learning_units, request.GET), } return render(request, "learning_units.html", context)
def learning_units_summary_list(request): a_user_person = find_by_user(request.user) learning_units_found = [] initial_academic_year = current_academic_year() if academic_calendar.is_academic_calendar_has_started( initial_academic_year, SUMMARY_COURSE_SUBMISSION): initial_academic_year = initial_academic_year.next() search_form = LearningUnitYearForm( request.GET or None, initial={'academic_year_id': initial_academic_year}) try: if search_form.is_valid(): learning_units_found_search = search_form.get_learning_units( requirement_entities=a_user_person.find_main_entities_version, luy_status=True) # TODO refactoring : too many queries learning_units_found = get_learning_units_and_summary_status( learning_units_found_search) check_if_display_message(request, learning_units_found_search) except TooManyResultsException: display_error_messages(request, 'too_many_results') responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list( learning_units_found) learning_units = sorted(learning_units_found, key=lambda learning_yr: learning_yr.acronym) errors = [ can_learning_unit_year_educational_information_be_udpated( learning_unit_year_id=luy.id) for luy in learning_units ] if request.GET.get('xls_status') == "xls_teaching_material": try: return generate_xls_teaching_material(request.user, learning_units_found) except ObjectDoesNotExist: display_warning_messages( request, _("the list to generate is empty.").capitalize()) form_comparison = SelectComparisonYears( academic_year=get_academic_year_of_reference(learning_units_found)) context = { 'form': search_form, 'formset': _get_formset(request, responsible_and_learning_unit_yr_list), 'learning_units_with_errors': list(zip(learning_units, errors)), 'search_type': SUMMARY_LIST, 'is_faculty_manager': a_user_person.is_faculty_manager(), 'form_comparison': form_comparison } return layout.render(request, "learning_units.html", context)
def learning_units_summary_list(request): a_user_person = find_by_user(request.user) learning_units_found = [] search_form = LearningUnitYearForm(request.GET or None) try: if search_form.is_valid(): learning_units_found_search = search_form.get_learning_units( requirement_entities=a_user_person.find_main_entities_version, luy_status=True) learning_units_found = get_learning_units_and_summary_status( learning_units_found_search) check_if_display_message(request, learning_units_found_search) except TooManyResultsException: display_error_messages(request, 'too_many_results') responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list( learning_units_found) context = { 'form': search_form, 'formset': _get_formset(request, responsible_and_learning_unit_yr_list), 'learning_units': sorted(learning_units_found, key=lambda learning_yr: learning_yr.acronym), 'experimental_phase': True, 'search_type': SUMMARY_LIST, 'is_faculty_manager': a_user_person.is_faculty_manager() } return layout.render(request, "learning_units.html", context)
def test_get_learning_unit_yr_list_with_summary_already_updated(self): learning_unit_year_updated = LearningUnitYearFakerFactory() learning_unit_year_updated.summary_status=True learning_units = get_responsible_and_learning_unit_yr_list([learning_unit_year_updated]) self.assertCountEqual(learning_units, [])
def test_get_learning_unit_yr_one_person_with_several_learning_unit_for_which_he_is_responsible(self): learning_units = get_responsible_and_learning_unit_yr_list( [self.learning_unit_year_1, self.learning_unit_year_3]) self.assertCountEqual(learning_units, [ {PERSON: self.tutor_lu1_1.person, LEARNING_UNIT_YEARS: [self.learning_unit_year_1, self.learning_unit_year_3]}])
def test_get_learning_unit_yr_list_with_two_responsibles(self): learning_units = get_responsible_and_learning_unit_yr_list([self.learning_unit_year_2]) self.assertCountEqual(learning_units, [ {PERSON: self.attribution_lu2_1.tutor.person, LEARNING_UNIT_YEARS: [self.learning_unit_year_2]}, {PERSON: self.attribution_lu2_2.tutor.person, LEARNING_UNIT_YEARS: [self.learning_unit_year_2]}])