Esempio n. 1
0
    def format_timetables(self, section, ws, offset):
        schedules = IScheduleContainer(section)
        if not schedules:
            return offset
        schedules = list(sorted(schedules.values(),
                                key=lambda s: s.timetable.__name__))
        for schedule in schedules:
            timetable = schedule.timetable
            self.write_header(ws, offset, 0,  "School Timetable")
            self.write(ws, offset, 1,  timetable.__name__)
            offset += 1

            self.write(ws, offset, 0,  "Consecutive periods as one")
            self.write(ws, offset, 1,
                       schedule.consecutive_periods_as_one and 'yes' or 'no')
            offset += 1

            self.write_header(ws, offset, 0,  "Day")
            self.write_header(ws, offset, 1,  "Period")
            offset += 1

            for period in schedule.periods:
                day = period.__parent__
                self.write(ws, offset, 0,  day.title)
                self.write(ws, offset, 1,  period.title)
                offset += 1
            offset += 1
        return offset
Esempio n. 2
0
    def format_timetables(self, section, ws, offset):
        schedules = IScheduleContainer(section)
        if not schedules:
            return offset
        schedules = list(
            sorted(schedules.values(), key=lambda s: s.timetable.__name__))
        for schedule in schedules:
            timetable = schedule.timetable
            self.write_header(ws, offset, 0, "School Timetable")
            self.write(ws, offset, 1, timetable.__name__)
            offset += 1

            self.write(ws, offset, 0, "Consecutive periods as one")
            self.write(ws, offset, 1,
                       schedule.consecutive_periods_as_one and 'yes' or 'no')
            offset += 1

            self.write_header(ws, offset, 0, "Day")
            self.write_header(ws, offset, 1, "Period")
            offset += 1

            for period in schedule.periods:
                day = period.__parent__
                self.write(ws, offset, 0, day.title)
                self.write(ws, offset, 1, period.title)
                offset += 1
            offset += 1
        return offset
Esempio n. 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 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)
Esempio n. 5
0
 def add(self, schedules):
     self._objects_added = []
     for section, schedule in self._objects_created:
         schedules = IScheduleContainer(section)
         chooser = INameChooser(schedules)
         name = chooser.chooseName('', schedule)
         schedules[name] = schedule
         self._objects_added.append(schedule)
Esempio n. 6
0
 def other_schedules(self):
     result = []
     n = 0
     int_ids = getUtility(IIntIds)
     while ('section-%d' % n in self.request and
            'schedule-%d' % n in self.request):
         section_id = self.request.get('section-%d' % n)
         schedule_name = self.request.get('schedule-%d' % n)
         n += 1
         try:
             section_id = int(section_id)
         except ValueError:
             continue
         section = int_ids.queryObject(section_id, None)
         if section is None:
             continue
         schedules = IScheduleContainer(section)
         schedule = schedules.get(schedule_name, None)
         if schedule is None:
             continue
         result.append(schedule)
     return result
Esempio n. 7
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
Esempio n. 8
0
    def export_section_timetables(self, wb):
        self.task_progress.force('export_section_timetables', active=True)
        ws = wb.add_sheet("SectionTimetables")

        year_sections = {}
        for year in ISchoolYearContainer(self.context).values():
            sections = year_sections[year] = {}
            for term in year.values():
                for section in ISectionContainer(term).values():
                    if not list(section.courses):
                        continue
                    timetables = []
                    for schedule in IScheduleContainer(section).values():
                        if schedule.timetable.__name__ is None:
                            # LP: #1281335
                            continue
                        parts = [schedule.timetable.__name__]
                        if schedule.consecutive_periods_as_one:
                            parts.append('yes')
                        else:
                            parts.append('no')
                        for period in schedule.periods:
                            day = period.__parent__
                            parts.append(day.title)
                            parts.append(period.title)
                        timetables.append(','.join(parts))
                    if not len(timetables):
                        continue
                    timetables = tuple(timetables)
                    timetable_sections = sections.setdefault(timetables, [])
                    timetable_sections.append(
                        (term.first, term, section.__name__, section))

        row = 0
        for ny, (year, sections) in enumerate(sorted(year_sections.items())):
            for nt, (timetables, timetable_sections) in enumerate(
                    sorted(sections.items())):
                row = self.format_timetable_sections(year, timetable_sections,
                                                     ws, row)
                row = self.format_timetables_block(timetables, ws, row)
                self.progress(
                    'export_section_timetables',
                    normalized_progress(ny, len(year_sections), nt,
                                        len(sections)))
        self.finish('export_section_timetables')
def printYearSections(schoolyear, with_ids=False):
    def sectionName(term, section):
        return '%s in %s' % (translate(section.label), term.title)

    for term in listTerms(schoolyear):
        sections = ISectionContainer(term)
        for s_name in sorted(sections):
            print '*' * 50
            section = sections[s_name]
            print sectionName(term, section)
            if with_ids:
                print '  ID:', section.__name__
            s_next = section.next
            if s_next is not None:
                n_term = ITerm(s_next)
                print '  next:', sectionName(n_term, s_next)
            print '  students:'
            for member in sorted(section.members, key=lambda m: m.__name__):
                print '   ', member.title
            schedules = IScheduleContainer(section)
            for key in sorted(schedules):
                print_schedule(schedules[key])