Exemplo n.º 1
0
 def importAllCourses(self):
     if not self.shouldImportAllCourses():
         return
     oldCourses = ICourseContainer(self.activeSchoolyear)
     newCourses = ICourseContainer(self.newSchoolyear)
     for id, course in oldCourses.items():
         newCourses[course.__name__] = new_course = Course(course.title, course.description)
         new_course.course_id = course.course_id
         new_course.government_id = course.government_id
         new_course.credits = course.credits
         for level in course.levels:
             new_course.levels.add(removeSecurityProxy(level))
Exemplo n.º 2
0
 def importAllCourses(self):
     if not self.shouldImportAllCourses():
         return
     oldCourses = ICourseContainer(self.activeSchoolyear)
     newCourses = ICourseContainer(self.newSchoolyear)
     for id, course in oldCourses.items():
         newCourses[course.__name__] = new_course = Course(
             course.title, course.description)
         new_course.course_id = course.course_id
         new_course.government_id = course.government_id
         new_course.credits = course.credits
         for level in course.levels:
             new_course.levels.add(removeSecurityProxy(level))
def setUpCourses(names):
    app = ISchoolToolApplication(None)
    CourseInit(app)()
    SectionInit(app)()
    courses = ICourseContainer(app)
    for name in names:
        courses[name.lower()] = Course(title=name)
Exemplo n.º 4
0
def setUpSchool(app):
    sy = ISchoolYearContainer(app)['2005'] = SchoolYear(
        '2005', date(2005, 1, 1), date(2005, 1, 30))

    term = sy['spring'] = Term('Spring', date(2005, 1, 1), date(2005, 1, 30))
    term.addWeekdays(0, 1, 2, 3, 4)

    pc = app['persons']
    teacher = pc['teacher'] = BasicPerson("teacher", "Mister", "T")
    s1 = pc['john'] = BasicPerson("john", "John", "Peterson")
    s2 = pc['pete'] = BasicPerson("pete", "Pete", "Johnson")

    contacts = IContactContainer(app)
    contact = Contact()
    contact.__name__ = 'pete_parent'
    contact.prefix = 'Ms.'
    contact.first_name = 'Susan'
    contact.middle_name = 'T.'
    contact.last_name = 'Johnson'
    contact.suffix = 'Jr.'
    contact.address_line_1 = '1 First St.'
    contact.address_line_2 = 'Apt. 1'
    contact.city = 'NY'
    contact.state = 'NY'
    contact.country = 'USA'
    contact.postal_code = '00000'
    contact.email = '*****@*****.**'
    contact.home_phone = '000-0000'
    contact.work_phone = '111-1111'
    contact.mobile_phone = '222-2222'
    contact.language = 'English'
    contacts['pete_parent'] = contact

    IContactable(s2).contacts.relate(contact, ACTIVE + PARENT, 'p')
    IContactable(s2).contacts.relate(IContact(teacher), ACTIVE + PARENT, 'p')

    d1 = IDemographics(s1)
    d1['ID'] = "112323"
    d1['ethnicity'] = u'Asian'
    d1['language'] = "English"
    d1['placeofbirth'] = "Humptington"
    d1['citizenship'] = "US"
    d2 = IDemographics(s2)
    d2['ID'] = "333655"
    d2['ethnicity'] = u'White'
    d2['language'] = "Brittish"
    d2['placeofbirth'] = "Providence"
    d2['citizenship'] = "UK"

    course = ICourseContainer(sy)['c1'] = Course("History")
Exemplo n.º 5
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')
Exemplo n.º 6
0
def getCourseContainerForTerm(term):
    return ICourseContainer(ISchoolYear(term))
Exemplo n.º 7
0
def getCourseContainerForApp(app):
    syc = ISchoolYearContainer(app)
    sy = syc.getActiveSchoolYear()
    if sy is not None:
        return ICourseContainer(sy)
Exemplo n.º 8
0
 def __call__(self):
     course_container = ICourseContainer(self.object)
     for course_id in list(course_container.keys()):
         del course_container[course_id]
     del course_container.__parent__[course_container.__name__]
Exemplo n.º 9
0
 def url(self):
     courses = ICourseContainer(self.schoolyear)
     return '%s/%s?camefrom=%s' % (
         absoluteURL(courses, self.request),
         'addSchoolToolCourse.html',
         absoluteURL(self.context, self.request))
Exemplo n.º 10
0
 def __call__(self):
     course_container = ICourseContainer(self.object)
     for course_id in list(course_container.keys()):
         del course_container[course_id]
     del course_container.__parent__[course_container.__name__]
Exemplo n.º 11
0
 def url(self):
     link = self.link
     if not link:
         return None
     courses = ICourseContainer(self.schoolyear)
     return "%s/%s" % (absoluteURL(courses, self.request), self.link)
Exemplo n.º 12
0
 def enabled(self):
     courses = ICourseContainer(self.schoolyear)
     if not flourish.canEdit(courses):
         return False
     return super(ImportCoursesLinkViewlet, self).enabled
Exemplo n.º 13
0
 def courses(self):
     return ICourseContainer(self.schoolyear, None)
Exemplo n.º 14
0
 def source(self):
     schoolyear = ISchoolYear(self.context)
     return ICourseContainer(schoolyear)
Exemplo n.º 15
0
 def container(self):
     schoolyear = self.schoolyear
     return ICourseContainer(schoolyear)
Exemplo n.º 16
0
 def hasCourses(self, schoolyear):
     courses = ICourseContainer(schoolyear)
     return bool(courses)
Exemplo n.º 17
0
    def importChunk(self, rows, line, dry_run=True):
        """Import a chunk of data that describes a section.

        You should run this method with dry_run=True before trying the
        real thing, or you might get in trouble.
        """
        terms = self.listTerms()
        row = rows[0]
        if len(row) not in (2, 2 + len(terms)):
            err_msg = _(
                'Wrong section header on line ${line_no} (it should contain a'
                ' course id, an instructor id and optional SchoolTool '
                'section IDs for each of the terms)',
                mapping={'line_no': line})
            return

        section_ids = None
        if len(row) == 2:
            course_id, instructor_id = row[:2]
        else:
            course_id = row[0]
            instructor_id = row[1]
            section_ids = row[2:]

        course = ICourseContainer(self.schoolyear).get(course_id, None)
        if course is None:
            self.errors.courses.append(course_id)

        instructor = self.persons.get(instructor_id, None)
        if instructor is None:
            self.errors.persons.append(instructor_id)

        line_ofs = 1
        finished = False

        timetables = ITimetableContainer(self.schoolyear)
        timetable = None
        periods = {}

        for row in rows[1:]:
            line_ofs += 1
            if row == ['***']:
                finished = True
                break

            if len(row) == 1:
                tt = timetables.get(row[0])
                if tt is None:
                    err_msg = _(
                        "Malformed line ${line_no}"
                        " (it should contain either a timetable id or"
                        " day id and a period id)",
                        mapping={'line_no': line + line_ofs - 1})
                    self.errors.generic.append(err_msg)
                    continue
                timetable = tt
                continue
            elif len(row) == 2:
                day_id, period_id = row
            else:
                err_msg = _(
                    "Malformed line ${line_no}"
                    " (it should contain either a timetable id or"
                    " day id and a period id)",
                    mapping={'line_no': line + line_ofs - 1})
                self.errors.generic.append(err_msg)
                continue

            if timetable is None:
                err_msg = _(
                    "Timetable id must be specified before"
                    " day id and a period id"
                    " at at line ${line_no}",
                    mapping={'line_no': line + line_ofs - 1})
                continue

            # check day_id
            ttday = None
            for day in timetable.periods.templates.values():
                if day.title == day_id:
                    ttday = day
                    break

            if ttday is None:
                errkey = (timetable.__name__, day_id)
                if errkey not in self.errors.day_ids:
                    self.errors.day_ids.append(errkey)
                continue

            ttperiod = None
            for period in ttday.values():
                if period.title == period_id:
                    ttperiod = period
                    break

            # check period_id
            if ttperiod is None:
                errkey = (timetable.__name__, day_id, period_id)
                if period_id not in self.errors.periods:
                    self.errors.periods.append(errkey)
                    continue

            if timetable.__name__ not in periods:
                periods[timetable.__name__] = []
            periods[timetable.__name__].append(period)

        if not finished:
            err_msg = _("Incomplete section description on line ${line}",
                        mapping={'line': line})
            self.errors.generic.append(err_msg)
            return
        if len(rows) == line_ofs:
            err_msg = _("No students in section (line ${line})",
                        mapping={'line': line + line_ofs})
            self.errors.generic.append(err_msg)
            return

        sections = []
        for n, term in enumerate(terms):
            section_container = ISectionContainer(term)
            section_id = None
            if section_ids is not None:
                section_id = section_ids[n]
            if (section_id is not None and section_id in section_container):
                section = section_container[section_id]
                self.updateSection(section,
                                   term,
                                   course,
                                   instructor,
                                   periods,
                                   dry_run=dry_run)
            else:
                section = self.createSection(term,
                                             course,
                                             instructor,
                                             periods,
                                             section_id=section_id,
                                             dry_run=dry_run)
            self.importPersons(rows[line_ofs:], section, dry_run=dry_run)
            if section is not None:
                sections.append(section)
        if not self.errors.anyErrors():
            for n, section in enumerate(sections[:-1]):
                section.next = sections[n + 1]
Exemplo n.º 18
0
 def getCourseContainer(cls, context, request):
     courses = ICourseContainer(cls.schoolyear, context)
     return courses