def check_edxapp_enrollment_is_valid(*args, **kwargs): """ backend function to check if enrollment is valid """ errors = [] is_active = kwargs.get("is_active", True) course_id = kwargs.get("course_id") force = kwargs.get('force', False) mode = kwargs.get("mode") program_uuid = kwargs.get('bundle_id') username = kwargs.get("username") email = kwargs.get("email") if program_uuid and course_id: return ['You have to provide a course_id or bundle_id but not both'] if not program_uuid and not course_id: return ['You have to provide a course_id or bundle_id'] if not email and not username: return ['Email or username needed'] if not check_edxapp_account_conflicts(email=email, username=username): return ['User not found'] if mode not in CourseMode.ALL_MODES: return ['Invalid mode given:' + mode] if course_id: if not validate_org(course_id): errors.append('Enrollment not allowed for given org') if course_id and not force: try: api.validate_course_mode(course_id, mode, is_active=is_active) except CourseModeNotFoundError: errors.append('Mode not found') except CourseNotFoundError: errors.append('Course not found') return errors
def ensure_valid_mode(cls, mode_slug, course_id): """ Ensures mode_slug is a valid mode for course_id. Will raise an error if invalid. """ if mode_slug is None: raise ValueError("Cannot create a CourseModeTarget without specifying a mode_slug.") try: validate_course_mode(unicode(course_id), mode_slug, include_expired=True) except CourseModeNotFoundError: raise ValueError( "Track {track} does not exist in course {course_id}".format( track=mode_slug, course_id=course_id ) )
def ensure_valid_mode(cls, mode_slug, course_id): """ Ensures mode_slug is a valid mode for course_id. Will raise an error if invalid. """ if mode_slug is None: raise ValueError("Cannot create a CourseModeTarget without specifying a mode_slug.") try: validate_course_mode(unicode(course_id), mode_slug, include_expired=True) except CourseModeNotFoundError: raise ValueError( "Track {track} does not exist in course {course_id}".format( track=mode_slug, course_id=course_id ) )