예제 #1
0
    def verify_canvas_course(self, course_id):
        """
        Verify that the Canvas course still exists, has a correct sis_id, and
        contains a UW Group section.
        """
        try:
            valid_adhoc_course_sis_id(course_id)
            (prefix, canvas_course_id) = course_id.split('_')
            canvas_course = get_course_by_id(canvas_course_id)
        except CoursePolicyException:
            canvas_course = get_course_by_sis_id(course_id)

        if canvas_course.sis_course_id is None:
            update_course_sis_id(canvas_course.course_id, course_id)

        group_section_id = group_section_sis_id(course_id)
        try:
            section = get_section_by_sis_id(group_section_id)
        except DataFailureException as err:
            if err.status == 404:
                self.data.add(
                    SectionCSV(section_id=group_section_id,
                               course_id=course_id,
                               name=group_section_name()))
            else:
                raise
예제 #2
0
    def _verify_canvas_course(self, course_id):
        try:
            valid_adhoc_course_sis_id(course_id)
            (prefix, canvas_course_id) = course_id.split("_")
            canvas_course = get_course_by_id(canvas_course_id)
        except CoursePolicyException:
            canvas_course = get_course_by_sis_id(course_id)

        if canvas_course.sis_course_id is None:
            update_course_sis_id(canvas_course.course_id, course_id)
예제 #3
0
    def get(self, request, *args, **kwargs):
        try:
            sis_id = kwargs.get('sis_id')
            canvas_id = re.match(r'^\d+$', sis_id)
            if canvas_id:
                course = get_course_by_id(canvas_id.group(0))
            else:
                course = get_course_by_sis_id(sis_id)

            course_rep = {
                'course_id': course.course_id,
                'sis_course_id': course.sis_course_id,
                'sws_course_id': course.sws_course_id(),
                'account_id': course.account_id,
                'term': {
                    'term_id': course.term.term_id,
                    'sis_term_id': course.term.sis_term_id,
                    'name': course.term.name
                },
                'course_name': course.name,
                'course_url': "{host}/courses/{course_id}".format(
                    host=getattr(settings, 'RESTCLIENTS_CANVAS_HOST', ''),
                    course_id=course.course_id),
                'workflow_state': course.workflow_state,
                'public_syllabus': course.public_syllabus,
                'syllabus_body': course.syllabus_body
            }

            if course.sis_course_id is not None:
                try:
                    model = Course.objects.get(course_id=course.sis_course_id)
                    course_rep.update(model.json_data(
                        include_sws_url=self.can_view_source_data(request)))
                except Course.DoesNotExist:
                    pass

            return self.json_response(course_rep)
        except Exception as e:
            return self.error_response(
                400, "Unable to retrieve course data: {}".format(e))
예제 #4
0
    def GET(self, request, **kwargs):
        try:
            sis_id = kwargs.get('sis_id')
            canvas_id = re.match(r'^\d+$', sis_id)
            if canvas_id:
                course = get_course_by_id(canvas_id.group(0))
            else:
                course = get_course_by_sis_id(sis_id)

            course_rep = {
                'course_id': course.course_id,
                'sis_course_id': course.sis_course_id,
                'sws_course_id': course.sws_course_id(),
                'account_id': course.account_id,
                'term': {
                    'term_id': course.term.term_id,
                    'sis_term_id': course.term.sis_term_id,
                    'name': course.term.name
                },
                'course_name': course.name,
                'course_url': "%s/courses/%s" % (
                    getattr(settings, 'RESTCLIENTS_CANVAS_HOST', ''),
                    course.course_id),
                'workflow_state': course.workflow_state,
                'public_syllabus': course.public_syllabus,
                'syllabus_body': course.syllabus_body
            }

            if course.sis_course_id is not None:
                try:
                    model = Course.objects.get(course_id=course.sis_course_id)
                    course_rep.update(model.json_data(can_view_source_data()))
                except Course.DoesNotExist:
                    pass

            return self.json_response(json.dumps(course_rep))
        except Exception as e:
            return self.json_response(
                '{"error": "Unable to retrieve course data: %s"' % (e) + ' }',
                status=400)