def clean(self): """ Validate the model. Currently, this only support courses, this can be extended whenever discussions are available in other contexts """ if not CourseOverview.course_exists(self.context_key): raise ValidationError('Context Key should be an existing learning context.')
def _ensure_course_exists(course_key, user_key_or_id): """ Log and raise an error if `course_key` does not refer to a real course run. `user_key_or_id` should be a non-PII value identifying the user that can be used in the log message. """ if CourseOverview.course_exists(course_key): return logger.error("Cannot enroll user={} in non-existent course={}".format( user_key_or_id, course_key, )) raise NonExistentCourseError
def wrapped_function(self, request, **kwargs): """ Wraps the given view_function. """ try: course_key = get_course_key(request, kwargs.get('course_id')) except InvalidKeyError as error: 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' ) from error if not CourseOverview.course_exists(course_key): raise self.api_error( status_code=status.HTTP_404_NOT_FOUND, developer_message=missing_course_error_message.format(course=str(course_key)), error_code='course_does_not_exist' ) return view_func(self, request, **kwargs)
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( # lint-amnesty, pylint: disable=raise-missing-from status_code=status.HTTP_404_NOT_FOUND, developer_message='The provided course key cannot be parsed.', error_code='invalid_course_key' ) if not CourseOverview.course_exists(course_key): raise self.api_error( status_code=status.HTTP_404_NOT_FOUND, developer_message="Requested grade for unknown course {course}".format(course=str(course_key)), error_code='course_does_not_exist' ) return view_func(self, request, **kwargs)