Beispiel #1
0
    def update(self):
        """Read and validate form data, and update model if necessary.

        Also choose the correct template to render.
        """
        self.field_errors = []
        self.template = self.select_template

        if 'CANCEL' in self.request:
            self.request.response.redirect(
                absoluteURL(self.context, self.request))
            return

        if 'date' in self.request:
            try:
                self.date = parse_date(self.request['date'])
            except ValueError:
                self.error = _("Invalid date. Please use YYYY-MM-DD format.")
            else:
                self.term = getTermForDate(self.date)
                if self.term is None:
                    self.error = _("The date does not belong to any term.")
                    self.date = None

        if self.date:
            self.template = self.form_template

        if self.date and 'SUBMIT' in self.request:
            replacements = self.extractMeetings()
            if self.field_errors:
                self.error = self.field_error_message
            else:
                self.updateExceptions(replacements)
                self.request.response.redirect(
                    absoluteURL(self.context, self.request))
Beispiel #2
0
 def __call__(self):
     term = getTermForDate(self.event.date)
     if term is None:
         return
     old_date = self.event.date
     new_date = self.event.replacement_date
     schoolyear = ISchoolYear(term)
     timetables = ITimetableContainer(schoolyear)
     for timetable in timetables.values():
         if IScheduleExceptions.providedBy(timetable):
             modified = False
             scheduled = DateRange(timetable.first, timetable.last)
             meeting_exceptions = PersistentList()
             if old_date in scheduled:
                 meetings = list(timetable.iterMeetings(old_date))
                 for meeting in meetings:
                     meeting_exceptions.append(
                         MeetingException(
                             meeting.dtstart.replace(year=new_date.year,
                                                     month=new_date.month,
                                                     day=new_date.day),
                             meeting.duration,
                             period=meeting.period,
                             meeting_id=meeting.meeting_id))
                 timetable.exceptions[old_date] = PersistentList()
                 modified = True
             if new_date in scheduled:
                 timetable.exceptions[new_date] = meeting_exceptions
                 modified = True
             if modified:
                 zope.lifecycleevent.modified(timetable)
Beispiel #3
0
    def update(self):
        """Read and validate form data, and update model if necessary.

        Also choose the correct template to render.
        """
        self.field_errors = []
        self.template = self.select_template

        if 'CANCEL' in self.request:
            self.request.response.redirect(
                absoluteURL(self.context, self.request))
            return

        if 'date' in self.request:
            try:
                self.date = parse_date(self.request['date'])
            except ValueError:
                self.error = _("Invalid date. Please use YYYY-MM-DD format.")
            else:
                self.term = getTermForDate(self.date)
                if self.term is None:
                    self.error = _("The date does not belong to any term.")
                    self.date = None

        if self.date:
            self.template = self.form_template

        if self.date and 'SUBMIT' in self.request:
            replacements = self.extractMeetings()
            if self.field_errors:
                self.error = self.field_error_message
            else:
                self.updateExceptions(replacements)
                self.request.response.redirect(
                    absoluteURL(self.context, self.request))
Beispiel #4
0
 def test_getTermForDate(self):
     self.assert_(term.getTermForDate(date(2004, 8, 31)) is None)
     self.assert_(term.getTermForDate(date(2004, 9, 1)) is self.term1)
     self.assert_(term.getTermForDate(date(2004, 11, 5)) is self.term1)
     self.assert_(term.getTermForDate(date(2004, 12, 20)) is self.term1)
     self.assert_(term.getTermForDate(date(2004, 12, 21)) is None)
     self.assert_(term.getTermForDate(date(2005, 3, 17)) is self.term2)
     self.assert_(term.getTermForDate(date(2005, 11, 5)) is None)
 def test_getTermForDate(self):
     self.assert_(term.getTermForDate(date(2004, 8, 31)) is None)
     self.assert_(term.getTermForDate(date(2004, 9, 1)) is self.term1)
     self.assert_(term.getTermForDate(date(2004, 11, 5)) is self.term1)
     self.assert_(term.getTermForDate(date(2004, 12, 20)) is self.term1)
     self.assert_(term.getTermForDate(date(2004, 12, 21)) is None)
     self.assert_(term.getTermForDate(date(2005, 3, 17)) is self.term2)
     self.assert_(term.getTermForDate(date(2005, 11, 5)) is None)
Beispiel #6
0
 def getDefaultMeetings(self, date, timezone):
     term = getTermForDate(date)
     if term is None:
         return []
     schoolyear = ISchoolYear(term)
     timetable_container = interfaces.ITimetableContainer(schoolyear)
     default_schedule = timetable_container.default
     if default_schedule is None:
         return []
     meetings = list(iterMeetingsInTimezone(
             default_schedule, timezone, date))
     return meetings
Beispiel #7
0
 def getDefaultMeetings(self, date, timezone):
     term = getTermForDate(date)
     if term is None:
         return []
     schoolyear = ISchoolYear(term)
     timetable_container = interfaces.ITimetableContainer(schoolyear)
     default_schedule = timetable_container.default
     if default_schedule is None:
         return []
     meetings = list(
         iterMeetingsInTimezone(default_schedule, timezone, date))
     return meetings