'Validate the course key.
Checks that the key format is valid and that
the course exists.  If not, displays an error message.
Arguments:
field_name (str): The name of the field to validate.
Returns:
CourseKey'

def clean_course_key(self):

    cleaned_id = self.cleaned_data['course_key']
    error_msg = _('COURSE    NOT    FOUND.        Please    check    that    the    course    ID    is    valid.')
    try:
        course_key = CourseKey.from_string(cleaned_id)
    except InvalidKeyError:
        raise forms.ValidationError(error_msg)
    if (not modulestore().has_course(course_key)):
        raise forms.ValidationError(error_msg)
    return course_key
