def unsubscribe_from_sequence( address ): # remove from sequence group try: user_signup = signup_model.get_signup(address) sequence_list = sequence_model.sequence_list_name(user_signup['sequence']) mailgun_api.remove_list_member(sequence_list, address) except: log.error(u"couldn't remove {0} from sequence list".format(address)) # remove from small groups # TODO: Can a user be subscribed to more than one group or more than one # sequence at the same time? groups = groups_model.get_member_groups(address) for group in groups: groups_model.remove_group_member(group['uri'], address) groups_model.sync_group_with_mailgun(group['uri']) # add signup to next sequence. signup_model.remove_signup_from_sequence(address)
def unsubscribe_user( address ): """ Unsubscribe user completely from the Mechanical Mooc """ # remove from sequence group try: user_signup = signup_model.get_signup(address) sequence_list = sequence_model.sequence_list_name(user_signup['sequence']) mailgun_api.remove_list_member(sequence_list, address) except: log.error(u"couldn't remove {0} from sequence list".format(address)) # remove from small groups groups = groups_model.get_member_groups(address) for group in groups: groups_model.remove_group_member(group['uri'], address) groups_model.sync_group_with_mailgun(group['uri']) # mark as unsubscribed in the signups signup_model.delete_signup(address)
def unsubscribe_user(address): """ Unsubscribe user completely from the Mechanical Mooc - all sequences """ # remove from sequence group signups = signup_model.get_all_user_signups(address) for user_signup in signups: sequence_list = sequence_model.sequence_list_name(user_signup["sequence"]) mailgun_api.remove_list_member(sequence_list, address) # remove from small groups groups = groups_model.get_member_groups(address) for group in groups: groups_model.remove_group_member(group["uri"], address) groups_model.sync_group_with_mailgun(group["uri"]) # mark as unsubscribed in the signups for user_signup in signups: signup_model.delete_signup(address, user_signup["sequence"]) mailgun_api.delete_all_unsubscribes(address)
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 unsubscribe_user(address): """ Unsubscribe user completely from the Mechanical Mooc - all sequences """ # remove from sequence group signups = signup_model.get_all_user_signups(address) for user_signup in signups: sequence_list = sequence_model.sequence_list_name( user_signup['sequence']) mailgun_api.remove_list_member(sequence_list, address) # remove from small groups groups = groups_model.get_member_groups(address) for group in groups: groups_model.remove_group_member(group['uri'], address) groups_model.sync_group_with_mailgun(group['uri']) # mark as unsubscribed in the signups for user_signup in signups: signup_model.delete_signup(address, user_signup['sequence']) mailgun_api.delete_all_unsubscribes(address)
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')