Exemple #1
0
    def _process_independent_study_section(self, section):
        """
        Generates the import data for an independent study section. This method
        will create course/section data for each instructor of the section,
        depending on whether section.independent_study_instructor_regid is set.
        """
        if section is None:
            return

        if not section.is_independent_study:
            raise CoursePolicyException(
                "Not an ind study section: {}".format(section.section_label()))

        match_independent_study = section.independent_study_instructor_regid
        for instructor in section.get_instructors():
            if (match_independent_study is not None and
                    match_independent_study != instructor.uwregid):
                continue

            section.independent_study_instructor_regid = instructor.uwregid

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

            self.data.add(TermCSV(section))
            self.data.add(SectionCSV(section=section))

            Course.objects.update_status(section)

            if is_active_section(section):
                self.add_teacher_enrollment_data(section, instructor)

                if self.include_enrollment:
                    self.add_registrations_by_section(section)
    def _process_independent_study_section(self, section):
        """
        Generates the import data for an independent study section. This method
        will create course/section data for each instructor of the section,
        depending on whether section.independent_study_instructor_regid is set.
        """
        if section is None:
            return

        if not section.is_independent_study:
            raise Exception("Not an independent study section: %s" % (
                section.section_label()))

        match_independent_study = section.independent_study_instructor_regid
        for instructor in section.get_instructors():
            if (match_independent_study is not None and
                    match_independent_study != instructor.uwregid):
                continue

            section.independent_study_instructor_regid = instructor.uwregid

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

            self.data.add(TermCSV(section))
            self.data.add(SectionCSV(section=section))

            Course.objects.update_status(section)

            if is_active_section(section):
                self.add_teacher_enrollment_data(section, instructor)

                if self.include_enrollment:
                    for registration in get_registrations_by_section(section):
                        self.add_student_enrollment_data(registration)
 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),
         ]
    def _process_linked_section(self, section, primary_instructors=[]):
        """
        Generates the import data for a non-independent study linked section.
        Linked (secondary) sections are added to sections.
        """
        if section is None:
            return

        if section.is_independent_study:
            raise Exception("Independent study section: %s" % (
                section.section_label()))

        if section.is_primary_section:
            raise Exception("Not a linked section: %s" % (
                section.section_label()))

        if self.data.add(SectionCSV(section=section)):
            if is_active_section(section):
                instructors = section.get_instructors()
                instructors.extend(primary_instructors)
                for instructor in instructors:
                    self.add_teacher_enrollment_data(section, instructor)

                if self.include_enrollment:
                    for registration in get_registrations_by_section(section):
                        self.add_student_enrollment_data(registration)

            Course.objects.update_status(section)
 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)]
    def _process(self, enrollment):
        if enrollment.queue_id is not None:
            self.queue_id = enrollment.queue_id

        try:
            enrollment.person = get_person_by_regid(enrollment.reg_id)

            section = self.get_section_resource_by_id(enrollment.course_id)
            section.independent_study_instructor_regid = (
                enrollment.instructor_reg_id)

            if not is_active_section(section):
                return

            enrollment.section = section

        except MissingLoginIdException as err:
            if enrollment.last_modified > self.retry_missing_id:
                self._requeue_enrollment_event(enrollment, err)
            else:
                self._skip_enrollment_event(enrollment, err)
            return
        except (UserPolicyException,
                InvalidCanvasIndependentStudyCourse) as err:
            self._skip_enrollment_event(enrollment, err)
            return
        except DataFailureException as err:
            if err.status == 404:
                self._skip_enrollment_event(enrollment, err)
            else:
                self._requeue_enrollment_event(enrollment, err)
            return

        if enrollment.is_instructor():
            self._process_instructor_enrollment(enrollment)
        else:  # student/auditor
            if len(section.linked_section_urls):
                # Don't enroll students into primary sections
                self._skip_enrollment_event(
                    enrollment, 'Section has linked sections')
            else:
                self._process_student_enrollment(enrollment)
 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),
         ]
    def _process(self, enrollment):
        try:
            enrollment.person = get_person_by_regid(enrollment.reg_id)

            section = self.get_section_resource_by_id(enrollment.course_id)
            section.independent_study_instructor_regid = (
                enrollment.instructor_reg_id)

            if not is_active_section(section):
                return

            enrollment.section = section

        except MissingLoginIdException as err:
            if enrollment.last_modified > self.retry_missing_id:
                self._requeue_enrollment_event(enrollment, err)
            else:
                self._skip_enrollment_event(enrollment, err)
            return
        except (UserPolicyException,
                InvalidCanvasIndependentStudyCourse) as err:
            self._skip_enrollment_event(enrollment, err)
            return
        except DataFailureException as err:
            if err.status == 404:
                self._skip_enrollment_event(enrollment, err)
            else:
                self._requeue_enrollment_event(enrollment, err)
            return

        if enrollment.is_instructor():
            self._process_instructor_enrollment(enrollment)
        else:  # student/auditor
            if len(section.linked_section_urls):
                # Don't enroll students into primary sections
                self._skip_enrollment_event(
                    enrollment, 'Section has linked sections')
            else:
                self._process_student_enrollment(enrollment)
Exemple #9
0
    def _process_linked_section(self, section, primary_instructors=[]):
        """
        Generates the import data for a non-independent study linked section.
        Linked (secondary) sections are added to sections.
        """
        if section is None:
            return

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

        if self.data.add(SectionCSV(section=section)):
            if is_active_section(section):
                instructors = section.get_instructors()
                instructors.extend(primary_instructors)
                for instructor in instructors:
                    self.add_teacher_enrollment_data(section, instructor)

                if self.include_enrollment:
                    self.add_registrations_by_section(section)

            Course.objects.update_status(section)
Exemple #10
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
    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 section.is_independent_study:
            raise Exception("Independent study section: %s" % (
                section.section_label()))

        if not section.is_primary_section:
            raise Exception("Not a primary section: %s" % (
                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):
            for url in section.linked_section_urls:
                try:
                    linked_section = get_section_by_url(url)
                    Course.objects.add_to_queue(linked_section, self.queue_id)
                except:
                    continue

                # Add primary section instructors to each linked section
                self._process_linked_section(linked_section,
                                             primary_instructors)
        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:
                    for registration in get_registrations_by_section(section):
                        self.add_student_enrollment_data(registration)

        # 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)
                Course.objects.add_to_queue(linked_section, self.queue_id)
                self._process_linked_section(linked_section,
                                             primary_instructors)
            except Exception as ex:
                Course.objects.remove_from_queue(linked_course_id, ex)
                continue

        # Iterate over joint sections
        for url in section.joint_section_urls:
            try:
                joint_section = get_section_by_url(url)
                model = Course.objects.add_to_queue(joint_section,
                                                    self.queue_id)
            except:
                continue

            try:
                self._process_primary_section(joint_section)
            except Exception as ex:
                Course.objects.remove_from_queue(model.course_id, ex)

        # 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)
                Course.objects.add_to_queue(joint_section, self.queue_id)
                self._process_primary_section(joint_section)

            except Exception as ex:
                Course.objects.remove_from_queue(joint_course_id, ex)

        self._process_xlists_for_section(section)

        # Find any sections that are manually cross-listed to this course,
        # so we can update enrollments for those
        for s in get_sis_sections_for_course(course_id):
            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