def evolveTimetables(app): # This import holds references to substitute classes # so that they can be pickled after modules are restored. from schooltool.generations.evolve36 import model modules = ModulesSnapshot() modules.mock_module('schooltool.timetable') modules.mock(model.substitutes) builders = [ SchoolTimetablesBuilder(), AppSchedulesBuilder(), AppTimetableCalendarBuilder(), ] for builder in builders: builder.read(app, BuildContext()) modules.restore() for builder in builders: builder.clean(app, BuildContext()) result = BuildContext() for builder in builders: built = builder.build(app, BuildContext(shared=result)) result.update(built) # Pickle stuff transaction.savepoint()
def build(self, timetables, context): # XXX: what if timezone is broken or outdated? if self.timezone is None: timezone = IApplicationPreferences(context.app).timezone else: timezone = self.timezone first, last = context.schoolyear.first, context.schoolyear.last timetable = Timetable( first, last, title=self.title, timezone=timezone) timetables[self.__name__] = timetable timetable.__parent__ = timetables built_periods = self.periods.build( timetable, context(timetables=timetables)) built_time_slots = self.time_slots.build( timetable, context(timetables=timetables)) built_exceptions = self.exceptions.build( timetable, context(timetables=timetables, period_map=built_periods.period_map)) if self.set_default: timetables.default = timetable return BuildContext(timetable=timetable, schema_id=self.__name__, period_map=built_periods.period_map)
def build(self, timetable, context): period_map = context.period_map tz = pytz.timezone(timetable.timezone) by_date = {} for day_templates in self.templates: for n, info in enumerate(day_templates): date, day_id, period_id, tstart, duration = info period_key = (day_id, period_id) period = period_map.get(period_key) dtstart = datetime.datetime.combine(date, tstart) dtstart = dtstart.replace(tzinfo=tz) if period is None: meeting_id = None else: meeting_id = timetable.periodMeetingId( date, period, n+1) meeting = MeetingException( dtstart, duration, period=period, meeting_id=meeting_id) if date not in by_date: by_date[date] = [] by_date[date].append(meeting) for date in by_date: timetable.exceptions[date] = PersistentList( sorted(by_date[date], key=lambda m: m.dtstart)) return BuildContext(exceptions=timetable.exceptions)
def build(self, timetable, context): schedule = createDayTemplates( timetable, SchoolDayTemplates, 'time_slots') for day in self.days: # XXX: title as key is not very safe, isn't it self.addDayTemplate(schedule.templates, day['title'], day) return BuildContext(schedule=schedule)
def build(self, timetable, context): schedule = createDayTemplates( timetable, WeekDayTemplates, 'time_slots') for weekday, day in enumerate(self.days): key = unicode(weekday) self.addDayTemplate(schedule.templates, key, day) return BuildContext(schedule=schedule)
def build(self, timetable, context): schedule = createDayTemplates( timetable, SchoolDayTemplates, 'periods') result = BuildContext(period_map={}) for day in self.days: # XXX: title as key is not very safe, isn't it built = self.addDayTemplate(schedule.templates, day['title'], day) result.period_map.update(built.period_map) return result(schedule=schedule)
def build(self, timetable, context): schedule = createDayTemplates( timetable, WeekDayTemplates, 'periods') result = BuildContext(period_map={}) for weekday in range(7): day = self.getDay(weekday) key = unicode(weekday) built = self.addDayTemplate(schedule.templates, key, day) result.period_map.update(built.period_map) return result(schedule=schedule)
def build(self, app, context): if APP_SCHEDULES_KEY not in app: app[APP_SCHEDULES_KEY] = SchoolToolSchedules() schedule_root = app[APP_SCHEDULES_KEY] result = BuildContext(schedule_map={}) for builder in self.builders: built = builder.build(schedule_root, context(app=app)) result.schedule_map.update(built.schedule_map) return result(schedule_root=schedule_root)
def addDayTemplate(self, templates, day_key, day): period_map = {} template = DayTemplate(title=day['title']) templates[day_key] = template name_chooser = INameChooser(template) for item in day['periods']: period = Period(title=item['title'], activity_type=item['activity_type']) key = name_chooser.chooseName('', period) template[key] = period period_map[(day['id'], item['title'])] = period return BuildContext(period_map=period_map)
def build(self, schedule_root, context): result = BuildContext(schedule_map={}) if not ISection.providedBy(self.owner): return result(schedules=None) owner_int_id = getUtility(IIntIds).getId(self.owner) key = unicode(owner_int_id) container = schedule_root[key] = ScheduleContainer() for builder in self.builders: built = builder.build( container, context(schedule_root=schedule_root, owner=self.owner)) result.schedule_map[built.unique_key] = built.schedule return result(schedules=container)
def build(self, app, context): if APP_TIMETABLES_KEY not in app: app[APP_TIMETABLES_KEY] = SchoolToolSchedules() timetable_root = app[APP_TIMETABLES_KEY] result = BuildContext(period_map={}) for builder in self.builders: built = builder.build(timetable_root, context(app=app)) year_period_map = dict( [((built.year_int_id, schema_id, day_id, period_id), period) for (schema_id, day_id, period_id), period in built.period_map.items()]) result.period_map.update(year_period_map) return result(timetable_root=timetable_root)
def build(self, timetable_root, context): key = unicode(self.year_int_id) container = timetable_root[key] = TimetableContainer() schoolyear = getUtility(IIntIds).getObject(self.year_int_id) result = BuildContext(period_map={}) for builder in self.timetables: built = builder.build( container, context(timetable_root=timetable_root, schoolyear=schoolyear)) schema_period_map = dict( [((built.schema_id, day_id, period_id), period) for (day_id, period_id), period in built.period_map.items()]) result.period_map.update(schema_period_map) return result(timetables=container, year_int_id=self.year_int_id)
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 build(self, app, context): result = BuildContext() for builder in self.builders: built = builder.build(context(app=app)) return result