def send_email( email_uri ): """ Send the email to the intended target audience """ email = mail_api.get_email(email_uri) if email['audience'] == 'groups': to_addresses = [g['address'] for g in group_api.get_groups(email['sequence'])] elif email['audience'] == 'individuals': to_addresses = [sequence_api.sequence_list_name(email['sequence'])] text_body = render_to_string('mail/email.txt', {'email': email}) html_body = render_to_string('mail/email.html', {'email': email}) batch_size = 1000 for i in range(0, len(to_addresses), batch_size): mailgun_api.send_mass_email( to_addresses[i:i+batch_size], settings.DEFAULT_FROM_EMAIL, email['subject'], text_body, html_body, email['tags'].split(','), sequence_api.sequence_campaign(email['sequence']) ) mail_api.mark_sent(email_uri)
def test_group_creation(self): for signup in randata.random_data(1000): signup_model.create_or_update_signup(**signup) group_data = models.prepare_groups(1) models.create_groups(group_data, 1) groups = group_model.get_groups(1) self.assertEqual(len(group_data), len(groups))
def test_group_creation(self): for signup in randata.random_data(1000): signup_model.create_or_update_signup(**signup) group_data = models.prepare_groups(1) models.create_groups(group_data, 'g-') groups = group_model.get_groups() self.assertEqual(len(group_data), len(groups)) for i, member in enumerate(groups[0]['members']): self.assertEqual(member, group_data[0]['members'][i]['email'])
def make_group_photos(sequence): groups = group_model.get_groups(sequence) photos = {} for group in groups: photos[group['uri']] = make_group_photo(group['uri']) photo_urls = {} for group_uri in photos: photo_urls[group_uri] = upload_to_s3(photos[group_uri], settings.AWS_S3_BUCKET) return photo_urls
def test_group_creation(self): for signup in randata.random_signup(1000): signup_model.create_or_update_signup(**signup) group_data = models.prepare_groups() models.create_groups(group_data, 'g-') groups = group_model.get_groups() self.assertEqual(len(group_data), len(groups)) for i, member in enumerate(groups[0]['members']): self.assertEqual(member, group_data[0]['members'][i]['email'])
def test_get_sequence_groups(self): group = group_model.create_group('*****@*****.**', 'The A team', 1) group = group_model.create_group('*****@*****.**', 'The B team', 1) group = group_model.create_group('*****@*****.**', 'The C team', 1) group = group_model.create_group('*****@*****.**', 'The D team', 1) group = group_model.create_group('*****@*****.**', 'The E team', 1) group = group_model.create_group('*****@*****.**', 'The A team', 2) group = group_model.create_group('*****@*****.**', 'The B team', 2) group = group_model.create_group('*****@*****.**', 'The C team', 2) s_1_groups = group_model.get_groups('1') self.assertIn('*****@*****.**', [group['address'] for group in s_1_groups])
def send_email(email_uri): """ Send the email to the intended target audience """ email = mail_api.get_email(email_uri) if email['audience'] == 'groups': to_address = ','.join( [g['address'] for g in group_api.get_groups(email['sequence'])]) elif email['audience'] == 'individuals': to_address = sequence_api.sequence_list_name(email['sequence']) text_body = render_to_string('mail/email.txt', {'email': email}) html_body = render_to_string('mail/email.html', {'email': email}) mailgun_api.send_email(to_address, settings.DEFAULT_FROM_EMAIL, email['subject'], text_body, html_body, email['tags'].split(','), sequence_api.sequence_campaign(email['sequence'])) mail_api.mark_sent(email_uri)
def do_grouping(sequence): groups = prepare_groups(sequence) create_groups(groups, sequence, 'Group {0}'.format(sequence)) # handle singups not in group signups = signup_model.get_signups(sequence) filter_group_preference = lambda su: su['questions']['groupRadios'] == False signups = filter(filter_group_preference, signups) group_address = 'ungrouped-s-{0}@{1}'.format(sequence, settings.EMAIL_DOMAIN) group_name = 'Ungrouped S{0}'.format(sequence, settings.EMAIL_DOMAIN) ungroup = group_model.create_group(group_address, group_name, sequence) for signup in signups: group_model.add_group_member(ungroup['uri'], signup['email']) # sync groups with mailgun for group in group_model.get_groups(sequence): group_model.add_group_member(group['uri'], settings.DEFAULT_FROM_EMAIL) group_model.sync_group_with_mailgun(group['uri']) # update access to group for ungrouped users mailgun_api.update_list(ungroup['address'], access_level='readonly')
def send_email( email_uri ): """ Send the email to the intended target audience """ email = mail_api.get_email(email_uri) if email['audience'] == 'groups': to_address = ','.join([g['address'] for g in group_api.get_groups(email['sequence'])]) elif email['audience'] == 'individuals': to_address = sequence_api.sequence_list_name(email['sequence']) text_body = render_to_string('mail/email.txt', {'email': email}) html_body = render_to_string('mail/email.html', {'email': email}) mailgun_api.send_email( to_address, settings.DEFAULT_FROM_EMAIL, email['subject'], text_body, html_body, email['tags'].split(','), sequence_api.sequence_campaign(email['sequence']) ) mail_api.mark_sent(email_uri)
def do_grouping(sequence): groups = prepare_groups(sequence) create_groups(groups, sequence, 'Group {0}'.format(sequence)) # handle singups not in group signups = signup_model.get_signups(sequence) filter_group_preference = lambda su: su['questions']['groupRadios' ] == False signups = filter(filter_group_preference, signups) group_address = 'ungrouped-s-{0}@{1}'.format(sequence, settings.EMAIL_DOMAIN) group_name = 'Ungrouped S{0}'.format(sequence, settings.EMAIL_DOMAIN) ungroup = group_model.create_group(group_address, group_name, sequence) for signup in signups: group_model.add_group_member(ungroup['uri'], signup['email']) # sync groups with mailgun for group in group_model.get_groups(sequence): group_model.add_group_member(group['uri'], settings.DEFAULT_FROM_EMAIL) group_model.sync_group_with_mailgun(group['uri']) # update access to group for ungrouped users mailgun_api.update_list(ungroup['address'], access_level='readonly')