def update_newsletter(sender, instance, **kwargs): print instance.user m= get_mailchimp_api() email={"email": instance.user.email } if not instance.active: m.lists.unsubscribe('0029e7e96a', email , delete_member=False) else: m.lists.subscribe('0029e7e96a', email , double_optin= False, update_existing= False, send_welcome=False)
def add_to_mailchimp(sender, user, **kwargs): newsletter, created = Newsletter.objects.get_or_create(user=user) u_email =user.email email = {"emails" : {"email": u_email}} m= get_mailchimp_api() try: abc = m.lists.member_info('0029e7e96a', email) # check mailchimp to see if emails on the list print abc except: abc = False if abc: for item in abc['data']: try: if item['status'] == "unsubscribed": newsletter.active = False newsletter.save() except: pass try: if item['status'] == "subscribed": newsletter.active = True newsletter.save() except: pass