def __call__(self, context): try: section = ISection(context) except (TypeError,): linked_activity = proxy.removeSecurityProxy(context) section = ISection(linked_activity.__parent__) return ExternalActivitiesSource(section)
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 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 contains(self, principal): setting = ConfigurableScheduleEditors(self.context) if not setting.contains(principal): return False section = ISection(self.context, None) if section is None: return False contains = InstructorsCrowd(section).contains(principal) return contains
def getScheduleCalendar(owner): if not ISection.providedBy(owner): return None annotations = IAnnotations(owner) try: return annotations[SCHEDULE_CALENDAR_KEY] except KeyError: calendar = ScheduleCalendar(owner) annotations[SCHEDULE_CALENDAR_KEY] = calendar return calendar
def enabled(self): gradebook = removeSecurityProxy(self.context) worksheet = gradebook.context if worksheet.hidden: return False courses = list(ISection(gradebook).courses) if not courses: return False for course in courses: if not flourish.canEdit(course): return False return super(DeployAsCourseWorksheetLinkViewlet, self).enabled
def enforceInstructionConstraints(event): """Enforce instruction constraints (IBeforeRelationshipEvent subscriber). """ if not IBeforeRelationshipEvent.providedBy(event): return if event.rel_type != URIInstruction: return if ((event.role1, event.role2) != (URIInstructor, URISection) and (event.role1, event.role2) != (URISection, URIInstructor)): raise InvalidRelationship('Instruction must have one instructor' ' and one section.') if not ISection.providedBy(event[URISection]): raise InvalidRelationship('Sections must provide ISection.')
def enforceCourseSectionConstraint(event): """Each CourseSections relationship requires one ICourse and one ISection """ if not IBeforeRelationshipEvent.providedBy(event): return if event.rel_type != URICourseSections: return if ((event.role1, event.role2) != (URICourse, URISectionOfCourse) and (event.role1, event.role2) != (URISectionOfCourse, URIInstructor)): raise InvalidRelationship('CourseSections must have one course' ' and one section.') if not ISection.providedBy(event[URISectionOfCourse]): raise InvalidRelationship('Sections must provide ISection.') if not ICourse.providedBy(event[URICourse]): raise InvalidRelationship('Course must provide ICourse.')
def courses(self): courses = [] request_courses = self.request.get('courses', []) for course in ISection(self.context).courses: if not flourish.canEdit(course): continue checked = ('SUBMIT' not in self.request or course.__name__ in request_courses) courses.append({ 'name': course.__name__, 'title': course.title, 'checked': checked and 'checked' or '', 'obj': course, }) return courses
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 updateStudentCalendars(event): """Add section's calendar to students overlaid calendars.""" if event.rel_type != URIMembership: return section = event[URIGroup] # Only continue if we're working with Sections rather than generic groups if not ISection.providedBy(section): return member = event[URIMember] calendar = ISchoolToolCalendar(section) if IRelationshipAddedEvent.providedBy(event): if IPerson.providedBy(member) and \ calendar not in member.overlaid_calendars: member.overlaid_calendars.add(calendar) elif IGroup.providedBy(member): for person in member.members: # we don't handle nested groups any more so there # shouldn't be more than one layer of groups if IPerson.providedBy(person) and \ calendar not in person.overlaid_calendars: person.overlaid_calendars.add(calendar) elif IRelationshipRemovedEvent.providedBy(event): if IPerson.providedBy(member): if calendar in member.overlaid_calendars: for group in member.groups: if group in section.members: return member.overlaid_calendars.remove(calendar) elif IGroup.providedBy(member): for person in member.members: if IPerson.providedBy(person): if calendar in person.overlaid_calendars: if person not in section.members: person.overlaid_calendars.remove(calendar)
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 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 getSelectedItems(self): """Return a list of groups the current user is a member of.""" return [group for group in self.context.groups if not ISection.providedBy(group)]
def getSelectedItems(self): groups = EditTemporalRelationships.getSelectedItems(self) return [ group for group in groups if not ISection.providedBy(group) and ISchoolYear(group.__parent__) in self.schoolyears ]
def schoolyear(self): return ISchoolYear(ISection(self.context))
def use_student_enrollment_states(other, collection): other = removeSecurityProxy(other) collection = removeSecurityProxy(collection) return (getattr(other, '__name__') == 'students' and collection.rel_type == URIMembership and IGroup.providedBy(other) and not ISection.providedBy(other))
def getSelectedItems(self): """Return a list of groups the current user is a member of.""" return [ group for group in self.context.groups if not ISection.providedBy(group) ]
def getSelectedItems(self): groups = EditTemporalRelationships.getSelectedItems(self) return [group for group in groups if not ISection.providedBy(group) and ISchoolYear(group.__parent__) in self.schoolyears]