def setup_learning_unit_year(academic_year, learning_unit, learning_container_year, learning_unit_year_subtype): create = False result = None end_year = learning_unit.end_year or compute_max_academic_year_adjournment() if learning_unit.start_year <= academic_year.year <= end_year: if learning_unit.periodicity == learning_unit_periodicity.BIENNIAL_ODD: if not (academic_year.year % 2): create = True elif learning_unit.periodicity == learning_unit_periodicity.BIENNIAL_EVEN: if academic_year.year % 2: create = True elif learning_unit.periodicity == learning_unit_periodicity.ANNUAL: create = True if create: if not learning_container_year: learning_container_year = LearningUnitsMixin.setup_learning_container_year( academic_year, learning_container_year_types.COURSE ) result = LearningUnitYearFactory( acronym=learning_unit.acronym, academic_year=academic_year, learning_unit=learning_unit, learning_container_year=learning_container_year, subtype=learning_unit_year_subtype ) return result
def _create_partim_process(request, learning_unit_year_parent, form): data = form.cleaned_data year = data['academic_year'].year parent_end_year = learning_unit_year_parent.learning_unit.end_year learning_container = learning_unit_year_parent.learning_container_year.learning_container learning_unit_created = create_learning_unit(data, learning_container, year, parent_end_year) while (year <= compute_max_academic_year_adjournment()) and ( not parent_end_year or year <= parent_end_year): academic_year = mdl.academic_year.find_academic_year_by_year(year) luy_created = create_learning_unit_partim_structure({ 'requirement_entity_version': data.get('requirement_entity'), 'additional_requirement_entity_version_1': data.get('additional_requirement_entity_1'), 'additional_requirement_entity_version_2': data.get('additional_requirement_entity_2'), 'allocation_entity_version': data.get('allocation_entity'), 'data': data, 'learning_container': learning_container, 'new_learning_unit': learning_unit_created, 'status': data['status'], 'academic_year': academic_year }) show_success_learning_unit_year_creation_message( request, luy_created, 'learning_unit_successfuly_created') year += 1
def clean_academic_year(self): academic_year = self.cleaned_data['academic_year'] academic_year_max = learning_unit.compute_max_academic_year_adjournment( ) if academic_year.year > academic_year_max: self.add_error( 'academic_year', _('learning_unit_creation_academic_year_max_error').format( academic_year_max)) return academic_year
def _check_extend_partim(last_learning_unit_year, new_academic_year): if not new_academic_year: # If there is no selected academic_year, we take the maximal value new_academic_year = AcademicYear.objects.get( year=compute_max_academic_year_adjournment() + 1) lu_parent = last_learning_unit_year.parent if last_learning_unit_year.is_partim() and lu_parent: if _get_actual_end_year( lu_parent.learning_unit) < new_academic_year.year: raise IntegrityError( _('parent_greater_than_partim') % { 'partim_end_year': new_academic_year, 'lu_parent': lu_parent.acronym })
def _get_academic_years(self): current_academic_year = academic_year.current_academic_year() min_year = current_academic_year.year max_year = compute_max_academic_year_adjournment() if self.learning_unit.start_year > min_year: min_year = self.learning_unit.start_year if is_old_learning_unit(self.learning_unit): raise ValueError( 'Learning_unit.end_year {} cannot be less than the current academic_year {}'.format( self.learning_unit.end_year, current_academic_year) ) if min_year > max_year: raise ValueError('Learning_unit {} cannot be modify'.format(self.learning_unit)) return academic_year.find_academic_years(start_year=min_year, end_year=max_year)
def _create_learning_unit_years_process(learning_unit_form, request): data = learning_unit_form.cleaned_data year = data['academic_year'].year new_learning_container = LearningContainer.objects.create() new_learning_unit = create_learning_unit(data, new_learning_container, year) first_learning_unit_year_id = None while year <= compute_max_academic_year_adjournment(): academic_year = mdl.academic_year.find_academic_year_by_year(year) new_learning_unit_year = create_learning_unit_year_structure( data, new_learning_container, new_learning_unit, academic_year) if not first_learning_unit_year_id: first_learning_unit_year_id = new_learning_unit_year.id show_success_learning_unit_year_creation_message( request, new_learning_unit_year, 'learning_unit_successfuly_created') year += 1 return first_learning_unit_year_id
def extend_learning_unit(learning_unit_to_edit, new_academic_year): result = [] last_learning_unit_year = LearningUnitYear.objects.filter( learning_unit=learning_unit_to_edit).order_by('academic_year').last() _check_extend_partim(last_learning_unit_year, new_academic_year) if not new_academic_year: # If there is no selected academic_year, we take the maximal value new_academic_year = AcademicYear.objects.get( year=compute_max_academic_year_adjournment()) with transaction.atomic(): for ac_year in _get_next_academic_years(learning_unit_to_edit, new_academic_year.year): new_luy = _duplicate_learning_unit_year(last_learning_unit_year, ac_year) result.append( create_learning_unit_year_creation_message( new_luy, 'learning_unit_successfuly_created')) return result
def _get_actual_end_year(learning_unit_to_edit): return learning_unit_to_edit.end_year or compute_max_academic_year_adjournment( ) + 1
def test_compute_max_academic_year_adjournment(self): self.assertEqual( learning_unit.compute_max_academic_year_adjournment(), self.current_academic_year.year + learning_unit.LEARNING_UNIT_CREATION_SPAN_YEARS)