def read(self, calendar, context): self.calendar = calendar self.events = [] for event in calendar: assert_not_broken(event) if not ITimetableCalendarEvent.providedBy(event): continue if event.__parent__ != calendar: # Event does not belong directly to this calendar # Probably this is a booked resource continue activity = event.activity schema = activity.timetable.schooltt year_int_id = int(schema.__parent__.__name__) period_key = (year_int_id, schema.__name__, event.day_id, event.period_id) timetable_key = (activity.timetable.term, activity.owner, activity.timetable.__name__) self.events.append({ 'dtstart': event.dtstart, 'duration': event.duration, 'unique_id': event.unique_id, 'timetable_key': timetable_key, 'period_key': period_key, # copy 'description': event.description, 'location': event.location, 'resources': event.resources, })
def read(self, schema, context): assert_not_broken(schema) self.timezone = unicode(schema.timezone) self.title = unicode(schema.title) self.__name__ = schema.__name__ model_name = schema.model.__class__.__name__ if model_name == 'SequentialDaysTimetableModel': self.periods = SchoolDayPeriodsBuilder() self.time_slots = WeekDayTimeSlotsBuilder() self.exceptions = SequentialDaysModelExceptions() elif model_name == 'SequentialDayIdBasedTimetableModel': self.periods = SchoolDayPeriodsBuilder() self.time_slots = SchoolDayTimeSlotsBuilder() self.exceptions = SequentialDayIdModelExceptions() elif model_name == 'WeeklyTimetableModel': self.periods = WeekDayPeriodsBuilder() self.time_slots = WeekDayTimeSlotsBuilder() self.exceptions = WeeklyModelExceptions() self.periods.read(schema, context()) self.time_slots.read(schema, context()) self.exceptions.read(schema, context())
def read(self, timetable_dict, context): self.builders = [] self.owner = timetable_dict.__parent__ for key, timetable in sorted(timetable_dict.items()): assert_not_broken(timetable) builder = ScheduleBuilder() builder.read(timetable, context(owner=self.owner, key=key)) self.builders.append(builder)
def read(self, schema, context): assert_not_broken(schema) self.days = [] for day_id, day in schema.items(): assert_not_broken(day) self.days.append({ 'id': day_id, 'title': unicode(day_id), 'periods': self.readPeriods(day), })
def read(self, schema, context): model = schema.model assert_not_broken(model) self.days = [] for day_id in model.timetableDayIds: template = model.dayTemplates[day_id] slots = self.readSlots(template) self.days.append({ 'title': unicode(day_id), 'time_slots': slots, })
def readSlots(self, school_day_template): if school_day_template is None: return [] assert_not_broken(school_day_template) assert_not_broken(*list(school_day_template)) slots = [{'tstart': slot.tstart, 'duration': slot.duration, 'activity_type': None, # XXX: !!! } for slot in school_day_template] return slots
def read(self, app, context): self.builders = [] candidates = findObjectsProviding(app, IAnnotatable) for candidate in candidates: assert_not_broken(candidate) annotations = IAnnotations(candidate, None) if annotations is None: continue calendar = annotations.get(ST_CALENDAR_KEY) if calendar is None: continue assert_not_broken(calendar) builder = CalendarBuilder() builder.read(calendar, context(app=app)) self.builders.append(builder)
def read(self, schema, context): model = schema.model assert_not_broken(model) self.days = [] for weekday in range(7): template = model.dayTemplates.get(weekday) if template is None: template = model.dayTemplates.get(None) slots = self.readSlots(template) self.days.append({ 'title': self.weekdays[weekday], 'time_slots': slots, })
def read(self, app, context): self.builders = [] # Find objects that may have provided IOwnTimetables candidates = findObjectsProviding(app, IAnnotatable) for candidate in candidates: assert_not_broken(candidate) annotations = IAnnotations(candidate, None) if annotations is None: continue timetable_dict = annotations.get(TIMETABLE_DICT_KEY) if timetable_dict is None: continue assert_not_broken(timetable_dict) builder = SchedulesBuilder() builder.read(timetable_dict, context(app=app)) self.builders.append(builder)
def read(self, timetable, context): self.data = {} for name in self.store_data: self.data[name] = getattr(timetable, name, None) for value in self.data.values(): assert_not_broken(value) schema = timetable.schooltt assert_not_broken(schema) self.schema_id = schema.__name__ self.year_int_id = int(schema.__parent__.__name__) self.selected_period_keys = [ (self.year_int_id, self.schema_id, day_id, period_id) for day_id, period_id, activity in timetable.activities()]
def read(self, schema_container, context): assert_not_broken(schema_container) self.year_int_id = context.year_int_id schoolyear = getUtility(IIntIds).getObject(self.year_int_id) default_id = schema_container._default_id self.timetables = [] for key, schema in list(schema_container.items()): assert_not_broken(schema) builder = TimetableBuilder() if (default_id is not None and default_id == key): builder.set_default = True builder.read(schema, context(schema_container=schema_container, schoolyear=schoolyear)) self.timetables.append(builder)
def read(self, timetable, context): self.data = {} for name in self.store_data: self.data[name] = getattr(timetable, name, None) for value in self.data.values(): assert_not_broken(value) schema = timetable.schooltt assert_not_broken(schema) self.schema_id = schema.__name__ self.year_int_id = int(schema.__parent__.__name__) self.selected_period_keys = [ (self.year_int_id, self.schema_id, day_id, period_id) for day_id, period_id, activity in timetable.activities() ]
def read(self, app, context): assert_not_broken(app) schema_root = app['schooltool.timetable.schooltt'] self.builders = [] for container in schema_root.values(): year_int_id = int(container.__name__) schoolyear = getUtility(IIntIds).queryObject(year_int_id) if schoolyear is None: # Dirty database: year was deleted, but timetable schemas # were left continue builder = TimetableContainerBuilder() assert_not_broken(container) builder.read(container, context(app=app, year_int_id=year_int_id)) self.builders.append(builder)