def check_instance(self): if self.instance.is_training(): pass elif self.instance.education_group_type.name in MiniTrainingType.to_postpone( ): pass else: raise NotPostponeError( _('You are not allowed to copy the content of this kind of education group.' )) if self.instance.academic_year.year < self.current_year.year: raise NotPostponeError( _("You are not allowed to postpone this training in the past.") ) if self.instance.academic_year.year > self.current_year.year: raise NotPostponeError( _("You are not allowed to postpone this training in the future." )) end_year = self.instance.education_group.end_year if end_year and end_year < self.next_academic_year.year: raise NotPostponeError( _("The end date of the education group is smaller than the year of postponement." )) if not self.instance.groupelementyear_set.exists(): raise NotPostponeError( _("This training has no content to postpone."))
def _postpone_child_branch(self, old_gr: GroupElementYear, new_gr: GroupElementYear) -> GroupElementYear: """ Unlike child leaf, the child branch must be postponed (recursively) """ old_egy = old_gr.child_branch new_egy = old_egy.next_year() if new_egy: is_empty = self._is_empty(new_egy) if new_gr.link_type == LinkTypes.REFERENCE.name and is_empty: self.warnings.append(ReferenceLinkEmptyWarning(new_egy)) elif not is_empty: if not (new_egy.is_training() or new_egy.education_group_type.name in MiniTrainingType.to_postpone()): self.warnings.append( EducationGroupYearNotEmptyWarning( new_egy, self.next_academic_year)) else: self._postpone(old_egy, new_egy) else: # If the education group does not exists for the next year, we have to postpone. new_egy = self._duplication_education_group_year(old_gr, old_egy) self.number_elements_created += 1 new_gr.child_branch = new_egy if new_egy and new_egy.education_group_type.name == MiniTrainingType.OPTION.name: self.postponed_options[new_egy.id] = new_gr if new_egy and new_gr.parent.education_group_type.name in TrainingType.finality_types( ): self.postponed_finalities.append(new_gr) return new_gr
def test_when_link_minor_to_minor_list_choice(self): minor_list_choice = GroupFactory( education_group_type__name=GroupType.MINOR_LIST_CHOICE.name) minor = MiniTrainingFactory(education_group_type__name=random.choice( MiniTrainingType.minors())) link = GroupElementYear(parent=minor_list_choice, child_branch=minor, link_type=None) link._clean_link_type() self.assertEqual(link.link_type, LinkTypes.REFERENCE.name)
def get_queryset(self, queryset=None): mini_training_to_postpone = EducationGroupYear.objects.filter( education_group=OuterRef("pk"), education_group_type__name__in=MiniTrainingType.to_postpone()) training_to_postpone = EducationGroupYear.objects.filter( education_group=OuterRef("pk"), education_group_type__category=TRAINING).exclude( acronym__icontains="11BA") education_group_years_to_postpone = mini_training_to_postpone | training_to_postpone # We need to postpone only trainings and some mini trainings return super().get_queryset(queryset).annotate( to_postpone=Exists(education_group_years_to_postpone)).filter( to_postpone=True)
def _display_education_group_year(egy: EducationGroupYear): if egy.is_training( ) or egy.education_group_type.name in MiniTrainingType.to_postpone(): return egy.verbose return egy.partial_acronym
def is_minor(self): return self.type in MiniTrainingType.minors()
def _clean_link_type(self): if getattr(self.parent, 'type', None) in [GroupType.MINOR_LIST_CHOICE.name, GroupType.MAJOR_LIST_CHOICE.name] and \ isinstance(self.child, EducationGroupYear) and self.child.type in MiniTrainingType.minors() + \ [MiniTrainingType.FSA_SPECIALITY.name, MiniTrainingType.DEEPENING.name]: self.link_type = LinkTypes.REFERENCE.name
def _clean_link_type(self): if getattr(self.parent, 'type', None) in [GroupType.MINOR_LIST_CHOICE.name, GroupType.MAJOR_LIST_CHOICE.name] and \ isinstance(self.child, EducationGroupYear) and self.child.type in MiniTrainingType.minors() + \ [MiniTrainingType.FSA_SPECIALITY.name, MiniTrainingType.DEEPENING.name]: self.link_type = LinkTypes.REFERENCE.name
def get_queryset(self, queryset=None): # We need to postpone only trainings and some mini trainings return super().get_queryset(queryset).filter( Q(educationgroupyear__education_group_type__category=TRAINING) | Q(educationgroupyear__education_group_type__name__in= MiniTrainingType.to_postpone())).distinct()
def get_queryset(self, queryset=None): # We need to postpone only trainings and some mini trainings return super().get_queryset(queryset).filter( Q(educationgroupyear__education_group_type__category=TRAINING) | Q(educationgroupyear__education_group_type__name__in=MiniTrainingType.to_postpone()) ).distinct()
def _show_free_text(self): return not self.object.is_common and self.object.education_group_type.name in itertools.chain( TrainingType.with_admission_condition(), MiniTrainingType.with_admission_condition() )
def show_admission_conditions(self): # @TODO: Need to refactor after business clarification return not self.object.is_main_common and \ self.object.education_group_type.name in itertools.chain(TrainingType.with_admission_condition(), MiniTrainingType.with_admission_condition()) \ and self.is_general_info_and_condition_admission_in_display_range()
def show_skills_and_achievements(self): return not self.object.is_common and \ self.object.education_group_type.name in itertools.chain(TrainingType.with_skills_achievements(), MiniTrainingType.with_admission_condition()) \ and self.is_general_info_and_condition_admission_in_display_range()
def is_minor(self): return self.education_group_type.name in MiniTrainingType.minors()