'Checking course-id format and course exists in module store.
This field can be null.'

def clean_course_id(self):

    if self.cleaned_data['course_id']:
        course_id = self.cleaned_data['course_id']
        try:
            course_key = CourseKey.from_string(course_id)
        except InvalidKeyError:
            raise forms.ValidationError(u'Invalid    CourseID.    Please    check    the    format    and    re-try.')
        if (not modulestore().has_course(course_key)):
            raise forms.ValidationError(u'Cannot    find    course    with    id    {}    in    the    modulestore'.format(course_id))
        return course_key
    return None
