def config_course_cohorts(course, is_cohorted, auto_cohorts=[], manual_cohorts=[], discussion_topics=[], cohorted_discussions=[], always_cohort_inline_discussions=True):
 def to_id(name):
  'Convert name to id.'
  return topic_name_to_id(course, name)
 set_course_cohort_settings(course.id, is_cohorted=is_cohorted, cohorted_discussions=[to_id(name) for name in cohorted_discussions], always_cohort_inline_discussions=always_cohort_inline_discussions)
 for cohort_name in auto_cohorts:
  cohort = CohortFactory(course_id=course.id, name=cohort_name)
  CourseCohortFactory(course_user_group=cohort, assignment_type=CourseCohort.RANDOM)
 for cohort_name in manual_cohorts:
  cohort = CohortFactory(course_id=course.id, name=cohort_name)
  CourseCohortFactory(course_user_group=cohort, assignment_type=CourseCohort.MANUAL)
 course.discussion_topics = dict(((name, {'sort_key': 'A', 'id': to_id(name)}) for name in discussion_topics))
 try:
  modulestore().update_item(course, ModuleStoreEnum.UserID.test)
 except NotImplementedError:
  pass

def config_course_cohorts ( course , is_cohorted , auto_cohorts = [ ] , manual_cohorts = [ ] , discussion_topics = [ ] , cohorted_discussions = [ ] , always_cohort_inline_discussions = True ) : def to_id ( name ) : return topic_name_to_id ( course , name ) set_course_cohort_settings ( course . id , is_cohorted = is_cohorted , cohorted_discussions = [ to_id ( name ) for name in cohorted_discussions ] , always_cohort_inline_discussions = always_cohort_inline_discussions ) for cohort_name in auto_cohorts : cohort = CohortFactory ( course_id = course . id , name = cohort_name ) CourseCohortFactory ( course_user_group = cohort , assignment_type = CourseCohort . RANDOM ) for cohort_name in manual_cohorts : cohort = CohortFactory ( course_id = course . id , name = cohort_name ) CourseCohortFactory ( course_user_group = cohort , assignment_type = CourseCohort . MANUAL ) course . discussion_topics = dict ( ( ( name , { 'sort_key' : 'A' , 'id' : to_id ( name ) } ) for name in discussion_topics ) ) try : modulestore ( ) . update_item ( course , ModuleStoreEnum . UserID . test ) except NotImplementedError : pass
set discussions and configure cohorts for a course .