def _get_course(self, request, course_id): """ Returns the course after parsing the id, checking access, and checking existence. """ try: course_key = get_course_key(request, course_id) except InvalidKeyError: raise self.api_error( status_code=status.HTTP_400_BAD_REQUEST, developer_message='The provided course key cannot be parsed.', error_code='invalid_course_key') if not has_access(request.user, 'staff', course_key): raise self.api_error( status_code=status.HTTP_403_FORBIDDEN, developer_message='The course does not exist.', error_code='user_or_course_does_not_exist', ) course = modulestore().get_course(course_key, depth=0) if not course: raise self.api_error( status_code=status.HTTP_404_NOT_FOUND, developer_message='The course does not exist.', error_code='user_or_course_does_not_exist', ) return course
def _get_course(self, request, course_id): """ Returns the course after parsing the id, checking access, and checking existence. """ try: course_key = get_course_key(request, course_id) except InvalidKeyError: raise self.api_error( status_code=status.HTTP_400_BAD_REQUEST, developer_message='The provided course key cannot be parsed.', error_code='invalid_course_key' ) if not has_access(request.user, 'staff', course_key): raise self.api_error( status_code=status.HTTP_403_FORBIDDEN, developer_message='The course does not exist.', error_code='user_or_course_does_not_exist', ) course = modulestore().get_course(course_key, depth=0) if not course: raise self.api_error( status_code=status.HTTP_404_NOT_FOUND, developer_message='The course does not exist.', error_code='user_or_course_does_not_exist', ) return course
def wrapped_function(self, request, **kwargs): """ Wraps the given view function. """ course_key = get_course_key(request, kwargs.get('course_id')) if not waffle_flags()[WRITABLE_GRADEBOOK].is_enabled(course_key): raise self.api_error( status_code=status.HTTP_403_FORBIDDEN, developer_message= 'The writable gradebook feature is not enabled for this course.', error_code='feature_not_enabled') return view_func(self, request, **kwargs)
def wrapped_function(self, request, **kwargs): """ Wraps the given view function. """ course_key = get_course_key(request, kwargs.get('course_id')) if not waffle_flags()[WRITABLE_GRADEBOOK].is_enabled(course_key): raise self.api_error( status_code=status.HTTP_403_FORBIDDEN, developer_message='The writable gradebook feature is not enabled for this course.', error_code='feature_not_enabled' ) return view_func(self, request, **kwargs)
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') course_key = get_course_key(request, course_id) if username: # If there is a username passed, get grade for a single user with self._get_user_or_raise(request, course_key) as grade_user: return self._get_single_user_grade(grade_user, course_key) else: # If no username passed, get paginated list of grades for all users in course return self._get_user_grades(course_key)
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') course_key = get_course_key(request, course_id) if username: # If there is a username passed, get grade for a single user with self._get_user_or_raise(request, course_key) as grade_user: return self._get_single_user_grade(grade_user, course_key) else: # If no username passed, get paginated list of grades for all users in course return self._get_user_grades(course_key)