Example #1
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
Example #2
0
    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)
Example #3
0
    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
Example #4
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
Example #5
0
 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)
Example #6
0
 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
Example #7
0
 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
Example #8
0
 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
Example #9
0
 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)
Example #10
0
 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
Example #11
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
Example #12
0
    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)
Example #13
0
 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
Example #14
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"))
Example #15
0
 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)
Example #16
0
    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')
Example #17
0
 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
Example #18
0
    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')
Example #19
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
Example #20
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
Example #21
0
 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)
Example #22
0
 def schoolyear(self):
     return ISchoolYear(self.context)
Example #23
0
def getGroupContainerForSection(section):
    sy = ISchoolYear(section)
    return IGroupContainer(sy)
Example #24
0
 def base_filename(self):
     terms = self.getTerms()
     if not terms:
         return 'report_sheets'
     schoolyear = ISchoolYear(terms[-1])
     return 'report_sheets_%s' % schoolyear.__name__
Example #25
0
 def schoolyear_id(self):
     sy = ISchoolYear(self.context, None)
     if sy is None:
         return u''
     return sy.__name__
Example #26
0
 def actualContext(self):
     current_term = getUtility(IDateManager).current_term
     if current_term is None:
         return ISchoolToolApplication(None)
     return ISchoolYear(current_term)
Example #27
0
 def school_year(self):
     term = self.term
     if term is None:
         return None
     return ISchoolYear(term, None)
Example #28
0
def getCourseContainerForSection(section):
    return interfaces.ICourseContainer(ISchoolYear(section))
Example #29
0
def getSchoolYearForSection(section):
    return ISchoolYear(ITerm(section.__parent__))
Example #30
0
def getSchoolYearForSectionContainer(section_container):
    return ISchoolYear(ITerm(section_container))