def get_connection(): global CONNECTION from mailchimp.chimp import Connection if not CONNECTION: CONNECTION = Connection(secure=SECURE) if not CONNECTION.is_connected: CONNECTION.connect(API_KEY) return CONNECTION
def dequeue(limit=None): from mailchimp.models import Queue for camp in Queue.objects.dequeue(limit): yield camp def is_queued_or_sent(object): from mailchimp.models import Queue, Campaign object_id = object.pk content_type = ContentType.objects.get_for_model(object) q = Queue.objects.filter(content_type=content_type, object_id=object_id) if q.count(): return q[0] c = Campaign.objects.filter(content_type=content_type, object_id=object_id) if c.count(): return c[0] return False # this has to be down here to prevent circular imports from mailchimp.chimp import Connection # open a non-connected connection (lazily connect on first get_connection call) CONNECTION = Connection(secure=SECURE) def get_connection(): if not CONNECTION.is_connected: CONNECTION.connect(API_KEY) return CONNECTION