def submit_bulk_course_email(request, course_key, email_id):
 email_obj = CourseEmail.objects.get(id=email_id)
 targets = Counter([target.target_type for target in email_obj.targets.all()])
 targets = [(target if (count <= 1) else '{} {}'.format(count, target)) for (target, count) in targets.iteritems()]
 task_type = 'bulk_course_email'
 task_class = send_bulk_course_email
 task_input = {'email_id': email_id, 'to_option': targets}
 task_key_stub = str(email_id)
 task_key = hashlib.md5(task_key_stub).hexdigest()
 return submit_task(request, task_type, task_class, course_key, task_input, task_key)

def submit_bulk_course_email ( request , course_key , email_id ) : email_obj = CourseEmail . objects . get ( id = email_id ) targets = Counter ( [ target . target_type for target in email_obj . targets . all ( ) ] ) targets = [ ( target if ( count <= 1 ) else '{} {}' . format ( count , target ) ) for ( target , count ) in targets . iteritems ( ) ] task_type = 'bulk_course_email' task_class = send_bulk_course_email task_input = { 'email_id' : email_id , 'to_option' : targets } task_key_stub = str ( email_id ) task_key = hashlib . md5 ( task_key_stub ) . hexdigest ( ) return submit_task ( request , task_type , task_class , course_key , task_input , task_key )
request to have bulk email sent as a background task .