コード例 #1
0
ファイル: views.py プロジェクト: hemant816/development
    def get(self, request, course_id=None):
        """
        Gets a course progress status.
        Args:
            request (Request): Django request object.
            course_id (string): URI element specifying the course location.
                                Can also be passed as a GET parameter instead.
        Return:
            A JSON serialized representation of the requesting user's current grade status.
        """
        username = request.GET.get('username')

        if not course_id:
            course_id = request.GET.get('course_id')

        # Validate course exists with provided course_id
        try:
            course_key = CourseKey.from_string(course_id)
        except InvalidKeyError:
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message='The provided course key cannot be parsed.',
                error_code='invalid_course_key'
            )

        if not CourseOverview.get_from_id_if_exists(course_key):
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message="Requested grade for unknown course {course}".format(course=course_id),
                error_code='course_does_not_exist'
            )

        if username:
            # If there is a username passed, get grade for a single user
            try:
                return self._get_single_user_grade(request, course_key)
            except USER_MODEL.DoesNotExist:
                raise self.api_error(
                    status_code=status.HTTP_404_NOT_FOUND,
                    developer_message='The user matching the requested username does not exist.',
                    error_code='user_does_not_exist'
                )
            except CourseEnrollment.DoesNotExist:
                raise self.api_error(
                    status_code=status.HTTP_404_NOT_FOUND,
                    developer_message='The user matching the requested username is not enrolled in this course',
                    error_code='user_not_enrolled'
                )
        else:
            # If no username passed, get paginated list of grades for all users in course
            return self._get_user_grades(course_key)
コード例 #2
0
    def get(self, request, course_id=None, username=None, *args, **kwargs):

        if not username:
            username = request.GET.get('username')

        if not course_id:
            course_id = request.GET.get('course_id')

        # Validate course exists with provided course_id
        try:
            course_key = CourseKey.from_string(course_id)
        except InvalidKeyError:
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message='The provided course key cannot be parsed.',
                error_code='invalid_course_key')

        if not CourseOverview.get_from_id_if_exists(course_key):
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message="Requested grade for unknown course {course}"
                .format(course=course_id),
                error_code='course_does_not_exist')

        self.course_section_mapping = _get_course_section_mapping(
            request, course_id)

        # if username:
        # If there is a username passed, get badge progress for a single user
        try:
            return Response(
                self._get_single_user_badge_progress(course_key, username))
        except USER_MODEL.DoesNotExist:
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message=
                'The user matching the requested username does not exist.',
                error_code='user_does_not_exist')
        except CourseEnrollment.DoesNotExist:
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message=
                'The user matching the requested username is not enrolled in this course',
                error_code='user_not_enrolled')
コード例 #3
0
ファイル: utils.py プロジェクト: zhulinhai/edx-platform
    def wrapped_function(self, request, **kwargs):
        """
        Wraps the given view_function.
        """
        try:
            course_key = get_course_key(request, kwargs.get('course_id'))
        except InvalidKeyError:
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message='The provided course key cannot be parsed.',
                error_code='invalid_course_key')

        if not CourseOverview.get_from_id_if_exists(course_key):
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message=u"Requested grade for unknown course {course}"
                .format(course=text_type(course_key)),
                error_code='course_does_not_exist')

        return view_func(self, request, **kwargs)
コード例 #4
0
ファイル: views.py プロジェクト: mitocw/edx-platform
    def wrapped_function(self, request, **kwargs):
        """
        Wraps the given view_function.
        """
        try:
            course_key = get_course_key(request, kwargs.get('course_id'))
        except InvalidKeyError:
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message='The provided course key cannot be parsed.',
                error_code='invalid_course_key'
            )

        if not CourseOverview.get_from_id_if_exists(course_key):
            raise self.api_error(
                status_code=status.HTTP_404_NOT_FOUND,
                developer_message="Requested grade for unknown course {course}".format(course=text_type(course_key)),
                error_code='course_does_not_exist'
            )

        return view_func(self, request, **kwargs)