def test_find_learning_unit_achievement(self): luy_achievement_fr_1 = LearningAchievementFactory(code_name=A_CODE_NAME, learning_unit_year=self.luy, language=self.language_fr) self.assertEqual(learning_achievement.find_learning_unit_achievement(luy_achievement_fr_1.learning_unit_year, luy_achievement_fr_1.language.code, 0), luy_achievement_fr_1) self.assertIsNone(learning_achievement.find_learning_unit_achievement(luy_achievement_fr_1.learning_unit_year, luy_achievement_fr_1.language.code, 100))
def operation(request, learning_achievement_id, operation_str): achievement_fr = get_object_or_404( LearningAchievement.objects.select_related( 'learning_unit_year__academic_year'), pk=learning_achievement_id) lu_yr_id = achievement_fr.learning_unit_year.id achievement_en = find_learning_unit_achievement( achievement_fr.consistency_id, achievement_fr.learning_unit_year, EN_CODE_LANGUAGE, achievement_fr.order) anchor = get_anchor_reference(operation_str, achievement_fr) filtered_achievements = list(filter(None, [achievement_fr, achievement_en])) last_academic_year = execute_operation(filtered_achievements, operation_str) if last_academic_year and last_academic_year.year <= achievement_fr.learning_unit_year.academic_year.year: display_success_messages(request, build_success_message(None, lu_yr_id, False)) else: display_success_messages( request, build_success_message(last_academic_year, lu_yr_id, True)) return HttpResponseRedirect( reverse(learning_unit_specifications, kwargs={'learning_unit_year_id': lu_yr_id}) + anchor)
def get_code_name(previous_achievement_fr, a_language_code): if not LearningAchievement.objects.filter( language__code=a_language_code, learning_unit_year=previous_achievement_fr.learning_unit_year).exists(): return previous_achievement_fr.code_name else: achievement_fr_next = find_learning_unit_achievement(previous_achievement_fr.learning_unit_year, previous_achievement_fr.language.code, previous_achievement_fr.order + 1) return achievement_fr_next.code_name if achievement_fr_next else ''
def get_code_name(previous_achievement_fr, a_language_code): if not LearningAchievement.objects.filter( language__code=a_language_code, learning_unit_year=previous_achievement_fr.learning_unit_year ).exists(): return previous_achievement_fr.code_name else: achievement_fr_next = find_learning_unit_achievement( previous_achievement_fr.learning_unit_year, previous_achievement_fr.language.code, previous_achievement_fr.order + 1) return achievement_fr_next.code_name if achievement_fr_next else ''
def operation(learning_achievement_id, operation_str): achievement_fr = get_object_or_404(LearningAchievement, pk=learning_achievement_id) lu_yr_id = achievement_fr.learning_unit_year.id achievement_en = find_learning_unit_achievement(achievement_fr.learning_unit_year, EN_CODE_LANGUAGE, achievement_fr.order) anchor = get_anchor_reference(operation_str, achievement_fr) execute_operation(achievement_fr, operation_str) execute_operation(achievement_en, operation_str) return HttpResponseRedirect(reverse(learning_unit_specifications, kwargs={'learning_unit_year_id': lu_yr_id}) + anchor)