def add_cohort(course_key, name, assignment_type):
 log.debug('Adding cohort %s to %s', name, course_key)
 if is_cohort_exists(course_key, name):
  raise ValueError(_('You cannot create two cohorts with the same name'))
 try:
  course = courses.get_course_by_id(course_key)
 except Http404:
  raise ValueError('Invalid course_key')
 cohort = CourseCohort.create(cohort_name=name, course_id=course.id, assignment_type=assignment_type).course_user_group
 tracker.emit('edx.cohort.creation_requested', {'cohort_name': cohort.name, 'cohort_id': cohort.id})
 return cohort

def add_cohort ( course_key , name , assignment_type ) : log . debug ( 'Adding cohort %s to %s' , name , course_key ) if is_cohort_exists ( course_key , name ) : raise ValueError ( _ ( 'You cannot create two cohorts with the same name' ) ) try : course = courses . get_course_by_id ( course_key ) except Http404 : raise ValueError ( 'Invalid course_key' ) cohort = CourseCohort . create ( cohort_name = name , course_id = course . id , assignment_type = assignment_type ) . course_user_group tracker . emit ( 'edx.cohort.creation_requested' , { 'cohort_name' : cohort . name , 'cohort_id' : cohort . id } ) return cohort
add a cohort to a course .