Exemple #1
0
    def test_with_end_date_inferior_to_offer_year_calendar_end_date(self):
        an_academic_calendar = AcademicCalendarFactory(
            academic_year=self.an_academic_year)
        an_offer_year = OfferYearFactory(academic_year=self.an_academic_year)
        an_offer_year_calendar = OfferYearCalendarFactory(
            academic_calendar=an_academic_calendar, offer_year=an_offer_year)

        form = AcademicCalendarForm(data={
            "academic_year":
            self.an_academic_year.pk,
            "title":
            "New title",
            "start_date":
            an_academic_calendar.start_date,
            "end_date":
            an_offer_year_calendar.end_date - datetime.timedelta(days=2)
        },
                                    instance=an_academic_calendar)
        self.assertFalse(form.is_valid())
        date_format = str(_('date_format'))
        self.assertEqual(
            form.errors['end_date'],
            _("The closure's date of '%s' of the academic calendar can't be "
              "lower than %s (end date of '%s' of the program '%s')") %
            (an_academic_calendar.title,
             an_offer_year_calendar.end_date.strftime(date_format),
             an_academic_calendar.title,
             an_offer_year_calendar.offer_year.acronym))
    def test_with_end_date_inferior_to_offer_year_calendar_end_date(self):
        an_academic_calendar = AcademicCalendarFactory(
            academic_year=self.an_academic_year)
        an_offer_year = OfferYearFactory(academic_year=self.an_academic_year)
        an_offer_year_calendar = OfferYearCalendarFactory(
            academic_calendar=an_academic_calendar, offer_year=an_offer_year)

        form = AcademicCalendarForm(data={
            "academic_year":
            self.an_academic_year.pk,
            "title":
            "New title",
            "start_date":
            an_academic_calendar.start_date,
            "end_date":
            an_offer_year_calendar.end_date - datetime.timedelta(days=2)
        },
                                    instance=an_academic_calendar)
        self.assertFalse(form.is_valid())
        date_format = str(_('date_format'))
        self.assertEqual(
            form.errors['end_date'], "%s." %
            (_('academic_calendar_offer_year_calendar_end_date_error') %
             (an_academic_calendar.title,
              an_offer_year_calendar.end_date.strftime(date_format),
              an_academic_calendar.title,
              an_offer_year_calendar.offer_year.acronym)))
 def test_with_start_and_end_dates_not_set(self):
     form = AcademicCalendarForm(data={
         "academic_year": self.an_academic_year.pk,
         "title": "Academic event",
         "description": "Description of an academic event"
     })
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['start_date'], _('dates_mandatory_error'))
 def test_with_correct_form(self):
     form = AcademicCalendarForm(data={
         "academic_year": self.an_academic_year.pk,
         "title": "Academic event",
         "description": "Description of an academic event",
         "start_date": datetime.date.today(),
         "end_date": datetime.date.today() + datetime.timedelta(days=2)
     })
     self.assertTrue(form.is_valid())
 def test_with_start_date_higher_than_end_date(self):
     form = AcademicCalendarForm(data={
         "academic_year": self.an_academic_year.pk,
         "title": "Academic event",
         "description": "Description of an academic event",
         "start_date": datetime.date.today(),
         "end_date": datetime.date.today() - datetime.timedelta(days=2)
     })
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['start_date'], _('start_date_must_be_lower_than_end_date'))
Exemple #6
0
def academic_calendar_form(request, academic_calendar_id):
    academic_calendar = mdl.academic_calendar.find_by_id(academic_calendar_id)
    if request.method == 'GET':
        academic_cal_form = AcademicCalendarForm(instance=academic_calendar)
    else:
        academic_cal_form = AcademicCalendarForm(data=request.POST, instance=academic_calendar)

        if academic_cal_form.is_valid():
            academic_cal_form.save()
            return academic_calendar_read(request, academic_cal_form.instance.id)
    return layout.render(request, "academic_calendar_form.html", {'form': academic_cal_form})
Exemple #7
0
def academic_calendar_form(request, academic_calendar_id):
    academic_calendar = get_object_or_none(AcademicCalendar,
                                           pk=academic_calendar_id)

    if request.method == 'GET':
        academic_cal_form = AcademicCalendarForm(instance=academic_calendar)
    else:
        academic_cal_form = AcademicCalendarForm(data=request.POST,
                                                 instance=academic_calendar)

        if academic_cal_form.is_valid():
            academic_cal_form.save()
            return academic_calendar_read(request,
                                          academic_cal_form.instance.id)
    return render(request, "academic_calendar/academic_calendar_form.html", {
        'form': academic_cal_form,
    })
Exemple #8
0
def academic_calendar_form(request, academic_calendar_id):
    if not request.user.is_superuser:
        raise PermissionDenied
    academic_calendar = get_object_or_none(AcademicCalendar,
                                           pk=academic_calendar_id)

    if request.method == 'GET':
        academic_cal_form = AcademicCalendarForm(instance=academic_calendar)
    else:
        academic_cal_form = AcademicCalendarForm(data=request.POST,
                                                 instance=academic_calendar)

        if academic_cal_form.is_valid():
            academic_cal_form.save()
            return academic_calendar_read(request,
                                          academic_cal_form.instance.id)
    return render(request, "academic_calendar/academic_calendar_form.html",
                  {'form': academic_cal_form})