Пример #1
0
    def createSection(self,
                      term,
                      course,
                      instructor,
                      periods,
                      section_id=None,
                      dry_run=True):
        """Create a section.

        `periods` is a list of tuples (day_id, period_id).

        A title is generated from the titles of `course` and `instructor`.
        If an existing section with the same title is found, it is used instead
        of creating a new one.

        The created section is returned, or None if dry_run is True.
        """
        if dry_run:
            return None

        sections = ISectionContainer(term)

        section = Section()
        chooser = INameChooser(sections)
        auto_name = chooser.chooseName('', section)
        section.title = u"%s (%s)" % (course.title, auto_name)
        if section_id is None:
            section_id = auto_name
        sections[section_id] = section

        # Establish links to course and to teacher
        if course not in section.courses:
            section.courses.add(course)
        if instructor not in section.instructors:
            section.instructors.add(instructor)

        timetable_container = ITimetableContainer(self.schoolyear)
        timetables = [timetable_container[ttid] for ttid in sorted(periods)]
        schedules = IScheduleContainer(section)
        for timetable in timetables:
            selected = periods[timetable.__name__]
            schedule = SelectedPeriodsSchedule(timetable,
                                               term.first,
                                               term.last,
                                               title=timetable.title,
                                               timezone=timetable.timezone)
            for period in selected:
                schedule.addPeriod(period)
            schedules[timetable.__name__] = schedule

        return section
Пример #2
0
 def create(self, data):
     timetable = data['timetable']
     schedule = SelectedPeriodsSchedule(
         timetable, data['first'], data['last'],
         title=timetable.title,
         timezone=timetable.timezone)
     return schedule
Пример #3
0
    def updateSection(self,
                      section,
                      term,
                      course,
                      instructor,
                      periods,
                      dry_run=True):
        """Create a section.

        `periods` is a list of tuples (day_id, period_id).

        A title is generated from the titles of `course` and `instructor`.
        If an existing section with the same title is found, it is used instead
        of creating a new one.

        The created section is returned, or None if dry_run is True.
        """
        if dry_run:
            return None

        # Establish links to course and to teacher
        for c in list(section.courses):
            if c is not course:
                section.remove(c)
        if course not in section.courses:
            section.courses.add(course)
        for i in list(section.instructors):
            if i is not instructor:
                section.instructor.remove(i)
        if instructor not in section.instructors:
            section.instructors.add(instructor)

        timetable_container = ITimetableContainer(self.schoolyear)
        timetables = [timetable_container[ttid] for ttid in sorted(periods)]
        schedules = IScheduleContainer(section)
        for timetable in timetables:
            selected = periods[timetable.__name__]
            schedule = None
            for s in schedules.values():
                if sameProxiedObjects(s.timetable, timetable):
                    schedule = s
                    break
            if schedule is None:
                schedule = SelectedPeriodsSchedule(timetable,
                                                   term.first,
                                                   term.last,
                                                   title=timetable.title,
                                                   timezone=timetable.timezone)
                for period in selected:
                    schedule.addPeriod(period)
                schedules[timetable.__name__] = schedule
            else:
                for period in schedule.periods:
                    if period not in selected:
                        schedule.removePeriod(period)
                for period in selected:
                    schedule.addPeriod(period)
    def createSection(self, term, course, instructor, periods,
                      section_id=None, dry_run=True):
        """Create a section.

        `periods` is a list of tuples (day_id, period_id).

        A title is generated from the titles of `course` and `instructor`.
        If an existing section with the same title is found, it is used instead
        of creating a new one.

        The created section is returned, or None if dry_run is True.
        """
        if dry_run:
            return None

        sections = ISectionContainer(term)

        section = Section()
        chooser = INameChooser(sections)
        auto_name = chooser.chooseName('', section)
        section.title = u"%s (%s)" % (course.title, auto_name)
        if section_id is None:
            section_id = auto_name
        sections[section_id] = section

        # Establish links to course and to teacher
        if course not in section.courses:
            section.courses.add(course)
        if instructor not in section.instructors:
            section.instructors.add(instructor)

        timetable_container = ITimetableContainer(self.schoolyear)
        timetables = [timetable_container[ttid]
                      for ttid in sorted(periods)]
        schedules = IScheduleContainer(section)
        for timetable in timetables:
            selected = periods[timetable.__name__]
            schedule = SelectedPeriodsSchedule(
                timetable, term.first, term.last,
                title=timetable.title, timezone=timetable.timezone)
            for period in selected:
                schedule.addPeriod(period)
            schedules[timetable.__name__] = schedule

        return section
Пример #5
0
    def build(self, container, context):
        timetables = context.shared.timetable_root[unicode(self.year_int_id)]
        timetable = timetables[self.schema_id]

        schedule = SelectedPeriodsSchedule(timetable,
                                           self.data['first'],
                                           self.data['last'],
                                           timezone=self.data['timezone']
                                           or 'UTC')

        result = BuildContext(schedule=schedule,
                              unique_key=(self.data['term'], context.owner,
                                          self.data['__name__']))

        schedule.consecutive_periods_as_one = \
            self.data['consecutive_periods_as_one']

        for key in self.selected_period_keys:
            period = context.shared.period_map[key]
            schedule.addPeriod(period)

        container[self.data['__name__']] = schedule
        return result(term=self.data['term'])
    def updateSection(self, section, term, course, instructor, periods,
                      dry_run=True):
        """Create a section.

        `periods` is a list of tuples (day_id, period_id).

        A title is generated from the titles of `course` and `instructor`.
        If an existing section with the same title is found, it is used instead
        of creating a new one.

        The created section is returned, or None if dry_run is True.
        """
        if dry_run:
            return None

        # Establish links to course and to teacher
        for c in list(section.courses):
            if c is not course:
                section.remove(c)
        if course not in section.courses:
            section.courses.add(course)
        for i in list(section.instructors):
            if i is not instructor:
                section.instructor.remove(i)
        if instructor not in section.instructors:
            section.instructors.add(instructor)

        timetable_container = ITimetableContainer(self.schoolyear)
        timetables = [timetable_container[ttid]
                      for ttid in sorted(periods)]
        schedules = IScheduleContainer(section)
        for timetable in timetables:
            selected = periods[timetable.__name__]
            schedule = None
            for s in schedules.values():
                if sameProxiedObjects(s.timetable, timetable):
                    schedule = s
                    break
            if schedule is None:
                schedule = SelectedPeriodsSchedule(
                    timetable, term.first, term.last,
                    title=timetable.title, timezone=timetable.timezone)
                for period in selected:
                    schedule.addPeriod(period)
                schedules[timetable.__name__] = schedule
            else:
                for period in schedule.periods:
                    if period not in selected:
                        schedule.removePeriod(period)
                for period in selected:
                    schedule.addPeriod(period)
    def build(self, container, context):
        timetables = context.shared.timetable_root[unicode(self.year_int_id)]
        timetable = timetables[self.schema_id]

        schedule = SelectedPeriodsSchedule(
            timetable, self.data['first'], self.data['last'],
            timezone=self.data['timezone'] or 'UTC')

        result = BuildContext(
            schedule=schedule,
            unique_key=(self.data['term'],
                        context.owner,
                        self.data['__name__'])
            )

        schedule.consecutive_periods_as_one = \
            self.data['consecutive_periods_as_one']

        for key in self.selected_period_keys:
            period = context.shared.period_map[key]
            schedule.addPeriod(period)

        container[self.data['__name__']] = schedule
        return result(term=self.data['term'])
Пример #8
0
 def create(self, data):
     section = self.owner
     linked = section.linked_sections
     terms = [(ITerm(s), s) for s in linked]
     terms = [(term, section) for term, section in terms
              if (term.first >= data['first'].first and
                  term.last <= data['last'].last)]
     self._objects_created = []
     timetable = data['timetable']
     for term, section in terms:
         schedule = SelectedPeriodsSchedule(
             timetable, term.first, term.last,
             title=timetable.title,
             timezone=timetable.timezone)
         self._objects_created.append((section, schedule))
     return self._objects_created