예제 #1
0
 def __init__(self, **kwargs):
     if kwargs.get("section"):
         section = kwargs.get("section")
         self.key = section.canvas_course_sis_id()
         self.data = [
             self.key,
             section_short_name(section),
             section_long_name(section),
             Curriculum.objects.canvas_account_id(section),
             term_sis_id(section),
             "active" if is_active_section(section) else "deleted",
             None,
             None,
         ]
     else:
         self.key = kwargs["course_id"]
         self.data = [
             self.key,
             kwargs["short_name"],
             kwargs["long_name"],
             kwargs["account_id"],
             kwargs["term_id"],
             kwargs.get("status", "active"),
             kwargs.get("start_date", None),
             kwargs.get("end_date", None),
         ]
예제 #2
0
 def __init__(self, **kwargs):
     if kwargs.get('section'):
         section = kwargs.get('section')
         self.key = section.canvas_section_sis_id()
         self.data = [self.key,
                      section.canvas_course_sis_id(),
                      section_short_name(section),
                      'active' if is_active_section(section) else 'deleted',
                      None, None]
     else:
         self.key = kwargs['section_id']
         self.data = [self.key, kwargs['course_id'], kwargs['name'],
                      kwargs.get('status', 'active'),
                      kwargs.get('start_date', None),
                      kwargs.get('end_date', None)]
예제 #3
0
 def __init__(self, **kwargs):
     if kwargs.get("section"):
         section = kwargs.get("section")
         self.key = section.canvas_section_sis_id()
         self.data = [
             self.key,
             section.canvas_course_sis_id(),
             section_short_name(section),
             "active" if is_active_section(section) else "deleted",
             None,
             None,
         ]
     else:
         self.key = kwargs["section_id"]
         self.data = [
             self.key,
             kwargs["course_id"],
             kwargs["name"],
             kwargs.get("status", "active"),
             kwargs.get("start_date", None),
             kwargs.get("end_date", None),
         ]
예제 #4
0
    def _process_primary_section(self, section):
        """
        Generates the import data for a non-independent study primary section.
        Primary sections are added to courses, linked (secondary) sections are
        added to sections.
        """
        if section is None:
            return

        if not section.is_primary_section or section.is_independent_study:
            raise CoursePolicyException("Not a primary section: {}".format(
                section.section_label()))

        if not self.data.add(CourseCSV(section=section)):
            return

        self.data.add(TermCSV(section))
        Course.objects.update_status(section)

        course_id = section.canvas_course_sis_id()
        primary_instructors = section.get_instructors()

        if len(section.linked_section_urls):
            dummy_section_id = '{}--'.format(course_id)
            try:
                canvas_section = get_section_by_sis_id(dummy_section_id)
                # Section has linked sections, but was originally
                # provisioned with a dummy section, which will be removed
                self.logger.info(
                    'Removed dummy section for {}'.format(course_id))
                self.data.add(SectionCSV(
                    section_id=dummy_section_id,
                    course_id=course_id,
                    name=section_short_name(section),
                    status='deleted'))
            except DataFailureException as ex:
                pass

            for url in section.linked_section_urls:
                try:
                    linked_course_id = section_id_from_url(url)
                    linked_section = self.get_section_resource_by_id(
                        linked_course_id)
                    # Add primary section instructors to each linked section
                    self._process_linked_section(linked_section,
                                                 primary_instructors)
                except (DataFailureException, CoursePolicyException):
                    pass

        else:
            self.data.add(SectionCSV(section=section))

            if is_active_section(section):
                for instructor in primary_instructors:
                    self.add_teacher_enrollment_data(section, instructor)

                if self.include_enrollment:
                    self.add_registrations_by_section(section)

        # Check for linked sections already in the Course table
        for linked_course_id in Course.objects.get_linked_course_ids(
                course_id):
            try:
                linked_section = self.get_section_resource_by_id(
                    linked_course_id)
                self._process_linked_section(linked_section,
                                             primary_instructors)
            except (DataFailureException, CoursePolicyException):
                pass

        # Iterate over joint sections
        for url in section.joint_section_urls:
            try:
                joint_course_id = section_id_from_url(url)
                joint_section = self.get_section_resource_by_id(
                    joint_course_id)
                self._process_primary_section(joint_section)
            except (DataFailureException, CoursePolicyException,
                    InvalidCanvasIndependentStudyCourse):
                pass

        # Joint sections already joined to this section in the Course table
        for joint_course_id in Course.objects.get_joint_course_ids(course_id):
            try:
                joint_section = self.get_section_resource_by_id(
                    joint_course_id)
                self._process_primary_section(joint_section)
            except (DataFailureException, CoursePolicyException,
                    InvalidCanvasIndependentStudyCourse):
                pass

        self._process_xlists_for_section(section)

        # Find any sections that are manually cross-listed to this course,
        # so we can update enrollments for those
        try:
            canvas_sections = get_sis_sections_for_course(course_id)
        except DataFailureException:
            canvas_sections = []

        for s in canvas_sections:
            try:
                course_model_id = re.sub(r'--$', '', s.sis_section_id)
                course = Course.objects.get(course_id=course_model_id,
                                            queue_id__isnull=True)
                self._process(course)
            except Course.DoesNotExist:
                pass