'Validate the course id'

def clean_course_id(self):

    cleaned_id = self.cleaned_data['course_id']
    try:
        course_key = CourseKey.from_string(cleaned_id)
    except InvalidKeyError:
        try:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(cleaned_id)
        except InvalidKeyError:
            msg = u'Course    id    invalid.'
            msg += u'    ---    Entered    course    id    was:    "{0}".    '.format(cleaned_id)
            msg += 'Please    recheck    that    you    have    supplied    a    valid    course    id.'
            raise forms.ValidationError(msg)
    if (not modulestore().has_course(course_key)):
        msg = u'COURSE    NOT    FOUND'
        msg += u'    ---    Entered    course    id    was:    "{0}".    '.format(course_key.to_deprecated_string())
        msg += 'Please    recheck    that    you    have    supplied    a    valid    course    id.'
        raise forms.ValidationError(msg)
    return course_key
