Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 def other_info(self):
     result = []
     for schedule in self.other_schedules:
         section = IHaveSchedule(schedule)
         term = ITerm(section)
         result.append({'owner': section, 'term': term})
     return result
Exemplo n.º 3
0
    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"))
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def DeployCourseWorksheetsOnSectionAdded(event):
    if event.rel_type != URICourseSections:
        return
    section = event[URISectionOfCourse]
    term = ITerm(section)
    course = event[URICourse]
    prefix = 'course_%s_%s' % (course.__name__, term.__name__)
    for deployedWorksheet in ICourseDeployedWorksheets(course).values():
        name = deployedWorksheet.__name__
        sheetPrefix = name[:name.rfind('_')]
        if sheetPrefix == prefix:
            worksheetCopy = Worksheet(deployedWorksheet.title)
            worksheetCopy.deployed = True
            IActivities(section)[deployedWorksheet.__name__] = worksheetCopy
            copyActivities(deployedWorksheet, worksheetCopy)
Exemplo n.º 6
0
 def create(self, data):
     section = self.owner
     linked = section.linked_sections
     terms = [(ITerm(s), s) for s in linked]
     terms = [(term, section) for term, section in terms
              if (term.first >= data['first'].first and
                  term.last <= data['last'].last)]
     self._objects_created = []
     timetable = data['timetable']
     for term, section in terms:
         schedule = SelectedPeriodsSchedule(
             timetable, term.first, term.last,
             title=timetable.title,
             timezone=timetable.timezone)
         self._objects_created.append((section, schedule))
     return self._objects_created
Exemplo n.º 7
0
 def sections(self):
     items = []
     for section in self.context.sections:
         term = ITerm(section, None)
         items.append({
             'section': section,
             'term': term,
             })
     def sortKey(item):
         # I consider it acceptable to violate security for sorting purposes
         # in this case.
         section = removeSecurityProxy(item['section'])
         term = removeSecurityProxy(item['term'])
         return u'%s%s%s' % (section.label,
                             term.first,
                             section.__name__)
     return sorted(items, key=sortKey)
Exemplo n.º 8
0
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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
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])
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
    def grouped_items(self):
        # XXX: this introduces dependency on terms.  A generic grouping
        #      would be more appropriate.
        items = super(CalendarOverlayView, self).items()
        non_term_items = []
        by_term = {}
        current_term = removeSecurityProxy(
            getUtility(IDateManager).current_term)

        for item in items:
            term = ITerm(item['calendar'].__parent__, None)
            unsecure_term = removeSecurityProxy(term)
            if unsecure_term is None:
                non_term_items.append(item)
                continue
            term_range = DateRange(term.first, term.last)
            view_range = self.view.cursor_range
            if term_range.overlaps(view_range):
                if unsecure_term not in by_term:
                    by_term[unsecure_term] = {
                        'group': term,
                        'items': [],
                        'expanded': unsecure_term is current_term,
                    }
                by_term[unsecure_term]['items'].append(item)

        order = sorted(by_term, key=lambda t: t.last, reverse=True)
        result = []
        if non_term_items:
            result.append({
                'group': None,
                'items': non_term_items,
                'expanded': True,
            })
        for term in order:
            result.append(by_term[term])
        return result
Exemplo n.º 13
0
def linkedSectionTermsVocabulary(context):
    section = interfaces.ISection(context)
    linked = section.linked_sections
    terms = [ITerm(s) for s in linked]
    return vocabulary_titled(terms)
Exemplo n.º 14
0
 def __init__(self, context):
     self.context = context
     terms = self.createTerms(ITerm(self.context.get('term')))
     zope.schema.vocabulary.SimpleVocabulary.__init__(self, terms)
Exemplo n.º 15
0
 def container(self):
     owner = IHaveSchedule(self.context)
     return ITimetableContainer(ISchoolYear(ITerm(owner)), {})
Exemplo n.º 16
0
def getTermForSection(section):
    return ITerm(section.__parent__)
Exemplo n.º 17
0
def getSchoolYearForSection(section):
    return ISchoolYear(ITerm(section.__parent__))
Exemplo n.º 18
0
def getSchoolYearForSectionContainer(section_container):
    return ISchoolYear(ITerm(section_container))
Exemplo n.º 19
0
 def term(self):
     return ITerm(self.owner, None)