@transaction.non_atomic_requests
@ensure_csrf_cookie
@require_POST
def add_users_to_cohort(request, course_key_string, cohort_id):
 course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
 get_course_with_access(request.user, 'staff', course_key)
 try:
  cohort = cohorts.get_cohort_by_id(course_key, cohort_id)
 except CourseUserGroup.DoesNotExist:
  raise Http404('Cohort (ID {cohort_id}) not found for {course_key_string}'.format(cohort_id=cohort_id, course_key_string=course_key_string))
 users = request.POST.get('users', '')
 added = []
 changed = []
 present = []
 unknown = []
 for username_or_email in split_by_comma_and_whitespace(users):
  if (not username_or_email):
   continue
  try:
   (user, previous_cohort) = cohorts.add_user_to_cohort(cohort, username_or_email)
   info = {'username': user.username, 'email': user.email}
   if previous_cohort:
    info['previous_cohort'] = previous_cohort
    changed.append(info)
   else:
    added.append(info)
  except ValueError:
   present.append(username_or_email)
  except User.DoesNotExist:
   unknown.append(username_or_email)
 return json_http_response({'success': True, 'added': added, 'changed': changed, 'present': present, 'unknown': unknown})

@ transaction . non_atomic_requests @ ensure_csrf_cookie @ require_POST def add_users_to_cohort ( request , course_key_string , cohort_id ) : course_key = SlashSeparatedCourseKey . from_deprecated_string ( course_key_string ) get_course_with_access ( request . user , 'staff' , course_key ) try : cohort = cohorts . get_cohort_by_id ( course_key , cohort_id ) except CourseUserGroup . DoesNotExist : raise Http404 ( 'Cohort (ID {cohort_id}) not found for {course_key_string}' . format ( cohort_id = cohort_id , course_key_string = course_key_string ) ) users = request . POST . get ( 'users' , '' ) added = [ ] changed = [ ] present = [ ] unknown = [ ] for username_or_email in split_by_comma_and_whitespace ( users ) : if ( not username_or_email ) : continue try : ( user , previous_cohort ) = cohorts . add_user_to_cohort ( cohort , username_or_email ) info = { 'username' : user . username , 'email' : user . email } if previous_cohort : info [ 'previous_cohort' ] = previous_cohort changed . append ( info ) else : added . append ( info ) except ValueError : present . append ( username_or_email ) except User . DoesNotExist : unknown . append ( username_or_email ) return json_http_response ( { 'success' : True , 'added' : added , 'changed' : changed , 'present' : present , 'unknown' : unknown } )
return json dict of: {success: true .