Esempio n. 1
0
    def export_sections_enrollment(self, wb):
        self.task_progress.force('export_sections_enrollment', active=True)
        ws = wb.add_sheet("SectionEnrollment")

        row = 0
        years = ISchoolYearContainer(self.context)
        total_years = len(years)
        for ny, year in enumerate(
                sorted(years.values(), key=lambda year: year.first)):
            total_terms = len(year)
            for nt, term in enumerate(
                    sorted(year.values(), key=lambda term: term.first)):
                sections = ISectionContainer(term)
                total_sections = len(sections)
                for ns, section in enumerate(
                        sorted(sections.values(),
                               key=lambda section: section.__name__)):
                    row = self.export_section_enrollment(ws,
                                                         year,
                                                         term,
                                                         section,
                                                         row=row)
                    self.progress(
                        'export_sections_enrollment',
                        normalized_progress(
                            ny,
                            total_years,
                            nt,
                            total_terms,
                            ns,
                            total_sections,
                        ))

        self.finish('export_sections_enrollment')
Esempio n. 2
0
 def sections(self):
     if self.has_schoolyear:
         result = []
         for term in self.schoolyear.values():
             sections = ISectionContainer(term)
             result.extend(list(sections.values()))
         return result
Esempio n. 3
0
    def export_sections_enrollment(self, wb):
        self.task_progress.force('export_sections_enrollment', active=True)
        ws = wb.add_sheet("SectionEnrollment")

        row = 0
        years = ISchoolYearContainer(self.context)
        total_years = len(years)
        for ny, year in enumerate(sorted(years.values(), key=lambda year: year.first)):
            total_terms = len(year)
            for nt, term in enumerate(sorted(year.values(), key=lambda term: term.first)):
                sections = ISectionContainer(term)
                total_sections = len(sections)
                for ns, section in enumerate(sorted(sections.values(),
                                                    key=lambda section: section.__name__)):
                    row = self.export_section_enrollment(
                        ws, year, term, section, row=row)
                    self.progress(
                        'export_sections_enrollment',
                        normalized_progress(
                            ny, total_years,
                            nt, total_terms,
                            ns, total_sections,
                            ))

        self.finish('export_sections_enrollment')
Esempio n. 4
0
    def deploy(self, course, term, template):
        # get the next index and title
        highest, title_index = 0, 0
        template_title = self.alternate_title
        for sheet in self.deployed(course).values():
            index = int(sheet.__name__[sheet.__name__.rfind('_') + 1:])
            if index > highest:
                highest = index
            new_index = self.getNewIndex(sheet, template_title)
            if new_index > title_index:
                title_index = new_index
        root = IGradebookRoot(ISchoolToolApplication(None))
        prefix = self.schoolyear.__name__ + '_'
        for sheet in root.deployed.values():
            if sheet.__name__.startswith(prefix):
                new_index = self.getNewIndex(sheet, template_title)
                if new_index > title_index:
                    title_index = new_index
        title = template_title
        if title_index:
            title += '-%s' % (title_index + 1)

        # copy worksheet template to the term or whole year
        if term:
            terms = [term]
        else:
            terms = self.schoolyear.values()
        for term in terms:
            deployedKey = 'course_%s_%s_%s' % (course.__name__, term.__name__,
                                               highest + 1)
            deployedWorksheet = Worksheet(title)
            self.deployed(course)[deployedKey] = deployedWorksheet
            copyActivities(removeSecurityProxy(template), deployedWorksheet)

            # now copy the template to all sections in the term
            sections = ISectionContainer(term)
            for section in sections.values():
                if course not in section.courses:
                    continue
                worksheetCopy = Worksheet(deployedWorksheet.title)
                worksheetCopy.deployed = True
                IActivities(section)[
                    deployedWorksheet.__name__] = worksheetCopy
                copyActivities(deployedWorksheet, worksheetCopy)