def is_student(person, only_active_year=False): active = get_active_year() person = removeSecurityProxy(person) group_relation = membership.Membership for link_info in group_relation.bind(member=person).all().relationships: target = removeSecurityProxy(link_info.target) schoolyear = None if interfaces.ISection.providedBy(target): schoolyear = ISchoolYear(ITerm(target)) elif target.__name__ == 'students': schoolyear = ISchoolYear(target.__parent__) if (schoolyear is not None and (not only_active_year or schoolyear == active)): return True return False
def update(self): self.collator = ICollator(self.request.locale) groups = [ group for group in self.context.groups if (canAccess(group, 'title') and not ISection.providedBy(group)) ] schoolyears_data = {} for group in groups: sy = ISchoolYear(group.__parent__) if sy not in schoolyears_data: schoolyears_data[sy] = [] schoolyears_data[sy].append(group) self.schoolyears = [] for sy in sorted(schoolyears_data, key=lambda x: x.first, reverse=True): sy_info = { 'obj': sy, 'groups': sorted(schoolyears_data[sy], cmp=self.collator.cmp, key=lambda x: x.title) } self.schoolyears.append(sy_info)
def format_group(self, group, ws, offset): fields = [ lambda i: ("Group Title", i.title, None), lambda i: ("ID", i.__name__, None), lambda i: ("School Year", ISchoolYear(i.__parent__).__name__, None), lambda i: ("Description", i.description, None) ] offset = self.listFields(group, fields, ws, offset) offset += self.print_table(self.format_membership_block( group.members, [Header('Members')]), ws, row=offset, col=0) offset += 1 leaders = IAsset(group).leaders offset += self.print_table(self.format_membership_block( leaders, [Header('Leaders')]), ws, row=offset, col=0) return offset
def sectionsAs(self, role_interface): schoolyears_data = {} for section in role_interface(self.context).sections(): sy = ISchoolYear(section) if sy not in schoolyears_data: schoolyears_data[sy] = {} term = ITerm(section) if term not in schoolyears_data[sy]: schoolyears_data[sy][term] = [] schoolyears_data[sy][term].append(section) result = [] for sy in sorted(schoolyears_data, key=lambda x:x.first, reverse=True): sy_info = {'obj': sy, 'terms': []} for term in sorted(schoolyears_data[sy], key=lambda x:x.first): sortingKey = lambda section:{'course': ', '.join([course.title for course in section.courses]), 'section_title': section.title} term_info = {'obj': term, 'sections': []} for section in sorted(schoolyears_data[sy][term], cmp=self.sortByCourseAndSection, key=sortingKey): section_info = {'obj': section, 'title': '%s -- %s' % \ (', '.join(course.title for course in section.courses), section.title)} term_info['sections'].append(section_info) sy_info['terms'].append(term_info) result.append(sy_info) return result
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)
def createTerms(self, term): result = [] result.append(self.createTerm( None, z3c.form.widget.SequenceWidget.noValueToken, _("Select a source"), )) root = IGradebookRoot(ISchoolToolApplication(None)) schoolyear = ISchoolYear(term) deployedKey = '%s_%s' % (schoolyear.__name__, term.__name__) for key in root.deployed: if key.startswith(deployedKey): deployedWorksheet = root.deployed[key] for activity in deployedWorksheet.values(): if ICommentScoreSystem.providedBy(activity.scoresystem): continue title = '%s - %s - %s' % (term.title, deployedWorksheet.title, activity.title) token = '%s-%s-%s' % (term.__name__, deployedWorksheet.__name__, activity.__name__) token=unicode(token).encode('punycode') result.append(self.createTerm( (deployedWorksheet, activity,), token, title, )) return result
def choices(self): """Get a list of the possible choices for report activities.""" result = { 'name': _('Choose a report activity'), 'value': '', } results = [result] root = IGradebookRoot(ISchoolToolApplication(None)) term = self.context schoolyear = ISchoolYear(term) deployedKey = '%s_%s' % (schoolyear.__name__, term.__name__) for key in root.deployed: if key.startswith(deployedKey): deployedWorksheet = root.deployed[key] for activity in deployedWorksheet.values(): if ICommentScoreSystem.providedBy(activity.scoresystem): continue name = '%s - %s - %s' % (term.title, deployedWorksheet.title, activity.title) value = '%s|%s|%s' % (term.__name__, deployedWorksheet.__name__, activity.__name__) result = { 'name': name, 'value': value, } results.append(result) return results
def done_link(self): schoolyear = ISchoolYear(self.context.__parent__) url = '%s/%s?schoolyear_id=%s' % ( absoluteURL(ISchoolToolApplication(None), self.request), 'courses', schoolyear.__name__) return url
def nextURL(self): if 'CONFIRM' in self.request: schoolyear = ISchoolYear(self.context) url = '%s/%s?schoolyear_id=%s' % (absoluteURL( ISchoolToolApplication(None), self.request), 'groups', schoolyear.__name__) return url return flourish.containers.ContainerDeleteView.nextURL(self)
def availableTerms(self): current_term = getUtility(IDateManager).current_term current_year = ISchoolYear(current_term) result = { 'title': current_year.__name__, 'value': '', 'selected': True, } results = [result] for term in current_year.values(): result = { 'title': term.title, 'value': '?term=' + term.__name__, 'selected': False, } results.append(result) return results
def is_teacher(person, only_active_year=False): active = get_active_year() person = removeSecurityProxy(person) is_wanted_group = lambda g: (g.__name__ == 'teachers' and not interfaces. ISection.providedBy(g)) group_relation = membership.Membership for link_info in group_relation.bind(member=person).all().relationships: target = removeSecurityProxy(link_info.target) if (is_wanted_group(target) and (not only_active_year or ISchoolYear(target.__parent__) == active)): return True for link_info in Instruction.bind(instructor=person).all().relationships: target = removeSecurityProxy(link_info.target) schoolyear = ISchoolYear(ITerm(target)) if not only_active_year or schoolyear == active: return True return False
def validate(self, value): super(TermBoundsValidator, self).validate(value) if ISchoolYear.providedBy(self.view.context): sy = self.view.context else: sy = self.view.context.__parent__ if value not in IDateRange(sy): raise DateOutOfYearBounds(self.view.context, value)
def base_filename(self): terms = self.getTerms() if not terms: return 'report_sheets' term = terms[-1] schoolyear = ISchoolYear(term) base_filename = 'report_sheets_%s_%s.xls' % (schoolyear.__name__, term.__name__) return base_filename
def __call__(self): if (self.event.first is None or self.event.second is None): return # unlinking sections first_term = ITerm(self.event.first) second_term = ITerm(self.event.second) if sameProxiedObjects(first_term, second_term): raise InvalidSectionLinkException( _("Cannot link sections in same term")) if not sameProxiedObjects(ISchoolYear(first_term), ISchoolYear(second_term)): raise InvalidSectionLinkException( _("Cannot link sections in different school years")) if not sameProxiedObjects(getNextTerm(first_term), second_term): raise InvalidSectionLinkException( _("Sections must be in consecutive terms"))
def nextURL(self): if 'CONFIRM' in self.request: schoolyear = ISchoolYear(self.context) params = {'schoolyear_id': schoolyear.__name__.encode('utf-8')} url = '%s/courses?%s' % ( absoluteURL(ISchoolToolApplication(None), self.request), urlencode(params)) return url return ContainerDeleteView.nextURL(self)
def export_terms(self, workbook, terms): self.task_progress.force('worksheets', active=True) terms = list(terms) for nt, self.term in enumerate(terms): self.schoolyear = ISchoolYear(self.term) self.activities = self.getActivities() self.export_term(workbook, nt, len(terms)) self.finish('worksheets')
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
def format_courses(self): def get_course_level(course): return ', '.join([l.__name__ for l in course.levels]) fields = [('School Year', Text, lambda c: ISchoolYear(c).__name__), ('ID', Text, attrgetter('__name__')), ('Title', Text, attrgetter('title')), ('Description', Text, attrgetter('description')), ('Local ID', Text, attrgetter('course_id')), ('Government ID', Text, attrgetter('government_id')), ('Credits', Text, attrgetter('credits')), ('Grade Level ID', Text, get_course_level)] school_years = ISchoolYearContainer(self.context).values() items = [] for year in school_years: items.extend([term for term in ICourseContainer(year).values()]) return self.format_table(fields, items, importer='export_courses')
def collectCourses(self): today = self.request.util.today student=removeSecurityProxy(self.context) codes = self.completed_state_codes completed_sections = [ relationship.target for relationship in Membership.relationships(member=student) if relationship.state.has(today, codes) ] schoolyears_data = {} for section in completed_sections: section = removeSecurityProxy(section) sy = ISchoolYear(section) if sy not in schoolyears_data: schoolyears_data[sy] = {} term = ITerm(section) if term not in schoolyears_data[sy]: schoolyears_data[sy][term] = [] schoolyears_data[sy][term].extend(section.courses) result = [] sortingKey = lambda course: self.collator.key(course.title) for sy in sorted(schoolyears_data, key=lambda x:x.first, reverse=True): sy_info = { 'obj': sy, 'css_class': 'active' if sy is self.schoolyear else 'inactive', 'terms': [], } for term in sorted(schoolyears_data[sy], key=lambda x:x.first, reverse=True): term_info = {'obj': term, 'courses': []} for course in sorted(schoolyears_data[sy][term], key=sortingKey): course_info = { 'obj': course, 'title': course.title, } term_info['courses'].append(course_info) sy_info['terms'].append(term_info) result.append(sy_info) return result
def sectionsAs(self, app_states, relationships): schoolyears_data = {} for link_info in relationships: if not ISection.providedBy(link_info.target): continue section = removeSecurityProxy(link_info.target) sy = ISchoolYear(section) if sy not in schoolyears_data: schoolyears_data[sy] = {} term = ITerm(section) if term not in schoolyears_data[sy]: schoolyears_data[sy][term] = [] schoolyears_data[sy][term].append((section, link_info)) result = [] for sy in sorted(schoolyears_data, key=lambda x:x.first, reverse=True): sy_info = { 'obj': sy, 'css_class': 'active' if sy is self.schoolyear else 'inactive', 'terms': [], } for term in sorted(schoolyears_data[sy], key=lambda x:x.first, reverse=True): term_info = {'obj': term, 'sections': []} for section, link_info in sorted(schoolyears_data[sy][term], key=self.sortingKey): states = self.section_current_states( section, app_states, link_info) section_info = { 'obj': section, 'title': section.title, 'states': states, } term_info['sections'].append(section_info) sy_info['terms'].append(term_info) result.append(sy_info) return result
def update(self): self.collator = ICollator(self.request.locale) relationships = Membership.bind( member=self.context).all().relationships group_states = self.app_states('group-membership') student_states = self.app_states('student-enrollment') schoolyears_data = {} for link_info in relationships: group = removeSecurityProxy(link_info.target) if ISection.providedBy(group) or not canAccess(group, 'title'): continue sy = ISchoolYear(group.__parent__) if sy not in schoolyears_data: schoolyears_data[sy] = [] schoolyears_data[sy].append((group, link_info)) self.schoolyears = [] for sy in sorted(schoolyears_data, key=lambda x: x.first, reverse=True): sy_info = { 'obj': sy, 'css_class': 'active' if sy is self.schoolyear else 'inactive', 'groups': [], } for group, link_info in sorted( schoolyears_data[sy], key=lambda x: self.collator.key(x[0].title)): is_students = group.__name__ == 'students' app_states = student_states if is_students else group_states states = self.group_current_states(link_info, app_states) group_info = { 'obj': group, 'title': group.title, 'states': states, } sy_info['groups'].append(group_info) self.schoolyears.append(sy_info)
def schoolyear(self): return ISchoolYear(self.context)
def getGroupContainerForSection(section): sy = ISchoolYear(section) return IGroupContainer(sy)
def base_filename(self): terms = self.getTerms() if not terms: return 'report_sheets' schoolyear = ISchoolYear(terms[-1]) return 'report_sheets_%s' % schoolyear.__name__
def schoolyear_id(self): sy = ISchoolYear(self.context, None) if sy is None: return u'' return sy.__name__
def actualContext(self): current_term = getUtility(IDateManager).current_term if current_term is None: return ISchoolToolApplication(None) return ISchoolYear(current_term)
def school_year(self): term = self.term if term is None: return None return ISchoolYear(term, None)
def getCourseContainerForSection(section): return interfaces.ICourseContainer(ISchoolYear(section))
def getSchoolYearForSection(section): return ISchoolYear(ITerm(section.__parent__))
def getSchoolYearForSectionContainer(section_container): return ISchoolYear(ITerm(section_container))