def _filter_optouts_from_recipients(to_list, course_id):
 optouts = Optout.objects.filter(course_id=course_id, user__in=[i['pk'] for i in to_list]).values_list('user__email', flat=True)
 optouts = set(optouts)
 num_optout = len(optouts)
 to_list = [recipient for recipient in to_list if (recipient['email'] not in optouts)]
 return (to_list, num_optout)

def _filter_optouts_from_recipients ( to_list , course_id ) : optouts = Optout . objects . filter ( course_id = course_id , user__in = [ i [ 'pk' ] for i in to_list ] ) . values_list ( 'user__email' , flat = True ) optouts = set ( optouts ) num_optout = len ( optouts ) to_list = [ recipient for recipient in to_list if ( recipient [ 'email' ] not in optouts ) ] return ( to_list , num_optout )
filters a recipient list based on student opt-outs for a given course .