Exemple #1
0
def education_group_edit_administrative_data(request, education_group_year_id):
    education_group_year = get_object_or_404(EducationGroupYear, pk=education_group_year_id)

    assert_category_of_education_group_year(education_group_year, (education_group_categories.TRAINING,))

    if not education_group_business.can_user_edit_administrative_data(request.user, education_group_year):
        raise PermissionDenied("Only program managers of the education group OR central manager "
                               "linked to entity can edit.")

    formset_session = AdministrativeDataFormset(request.POST or None,
                                                form_kwargs={'education_group_year': education_group_year})

    offer_year_calendar = mdl.offer_year_calendar.search(education_group_year_id=education_group_year_id,
                                                         academic_calendar_reference=academic_calendar_type.COURSE_ENROLLMENT).first()

    course_enrollment = CourseEnrollmentForm(request.POST or None, instance=offer_year_calendar)

    course_enrollment_validity = course_enrollment.is_valid()
    formset_session_validity = formset_session.is_valid()

    if course_enrollment_validity and formset_session_validity:
        formset_session.save()
        course_enrollment.save()
        messages.add_message(request, messages.SUCCESS, _('The administrative data has been successfully modified'))
        return HttpResponseRedirect(reverse('education_group_administrative', args=(education_group_year_id,)))

    return layout.render(request, "education_group/tab_edit_administrative_data.html", locals())
    def test_clean_with_validation_error_in_date(self):
        education_group_yr = EducationGroupYearFactory(academic_year=self.academic_year)
        AcademicCalendarFactory(reference=academic_calendar_type.COURSE_ENROLLMENT,
                                academic_year=self.academic_year)

        exam_enrollment_start = '20/12/{}'.format(self.academic_year.year)
        exam_enrollment_end = '15/01/{}'.format(self.academic_year.year)

        form = CourseEnrollmentForm(data={"range_date": exam_enrollment_start + ' - ' + exam_enrollment_end},
                                    instance=None, education_group_yr=education_group_yr)
        form.is_valid()
        self.assertEqual(form.errors["range_date"][0],
                         _('The start date must be equals or lower than the end date'))
    def test_clean(self):
        education_group_yr = EducationGroupYearFactory(academic_year=self.academic_year)
        academic_cal_course_enrollment = AcademicCalendarFactory(reference=academic_calendar_type.COURSE_ENROLLMENT,
                                                                 academic_year=self.academic_year)

        exam_enrollment_start = '20/12/{}'.format(self.academic_year.year)
        exam_enrollment_end = '15/01/{}'.format(self.academic_year.year+1)

        form = CourseEnrollmentForm(data={"range_date": exam_enrollment_start + ' - ' + exam_enrollment_end},
                                    instance=None, education_group_yr=education_group_yr)
        form.is_valid()
        self.assertEqual(form.instance.education_group_year, education_group_yr)
        self.assertEqual(form.instance.academic_calendar, academic_cal_course_enrollment)
    def test_clean_with_validation_error(self):
        education_group_yr = EducationGroupYearFactory(academic_year=self.academic_year)
        AcademicCalendarFactory(reference=academic_calendar_type.COURSE_ENROLLMENT,
                                academic_year=self.academic_year)

        exam_enrollment_start = '20/12/{}'.format(self.academic_year.year-2)
        exam_enrollment_end = '15/01/{}'.format(self.academic_year.year-1)

        form = CourseEnrollmentForm(data={"range_date": exam_enrollment_start + ' - ' + exam_enrollment_end},
                                    instance=None, education_group_yr=education_group_yr)
        form.is_valid()

        self.assertEqual(form.errors["range_date"][0],
                         "{} doit être comprise entre {} et {}"
                         .format(exam_enrollment_start,
                                 self.academic_year.start_date.strftime(DATE_FORMAT),
                                 self.academic_year.end_date.strftime(DATE_FORMAT)))