|
|
@ -64,6 +64,7 @@ class MailingContact(models.Model): |
|
|
|
|
|
|
|
def get_info_sendinblue_contact(self): |
|
|
|
#https://developers.sendinblue.com/reference/getfolders-1 |
|
|
|
_logger.info('get_info_sendinblue_contact') |
|
|
|
f = open(SENDINBLUE_ACCOUNT_FILE) |
|
|
|
data = json.load(f) |
|
|
|
configuration = sib_api_v3_sdk.Configuration() |
|
|
@ -72,16 +73,21 @@ class MailingContact(models.Model): |
|
|
|
email = self.email |
|
|
|
|
|
|
|
try: |
|
|
|
_logger.info('get_info_sendinblue_contact -1') |
|
|
|
api_response = api_instance.get_contact_info(email) |
|
|
|
|
|
|
|
|
|
|
|
return (api_response) |
|
|
|
except ApiException as e: |
|
|
|
_logger.info('get_info_sendinblue_contact -2') |
|
|
|
#print("Exception when calling ContactsApi->get_contact_info: %s\n" % e) |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def create_sendinblue_contact(self): |
|
|
|
_logger.info('create_sendinblue_contact') |
|
|
|
if self.email and self.list_ids: |
|
|
|
_logger.info('create_sendinblue_contact -1') |
|
|
|
configuration = sib_api_v3_sdk.Configuration() |
|
|
|
#https://developers.sendinblue.com/reference/getfolders-1 |
|
|
|
f = open(SENDINBLUE_ACCOUNT_FILE) |
|
|
@ -95,6 +101,7 @@ class MailingContact(models.Model): |
|
|
|
#si le contact existe dans sendinblue, on lui rajoute la nouvelle |
|
|
|
# liste de diffusion |
|
|
|
if res: |
|
|
|
_logger.info('create_sendinblue_contact -2') |
|
|
|
for id in self.list_ids: |
|
|
|
if id.id_sendinblue_list: |
|
|
|
if not id.id_sendinblue_list in res.list_ids: |
|
|
@ -108,13 +115,14 @@ class MailingContact(models.Model): |
|
|
|
return True |
|
|
|
#si le contact n'existe pas dans sendinblue, on le créé |
|
|
|
else: |
|
|
|
_logger.info('create_sendinblue_contact -3') |
|
|
|
for id in self.list_ids: |
|
|
|
list_ids.append(int(id.id_sendinblue_list)) |
|
|
|
if list_ids!=[]: |
|
|
|
create_contact = sib_api_v3_sdk.CreateContact(email=self.email, list_ids=list_ids) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
_logger.info('create_sendinblue_contact -4') |
|
|
|
api_response = api_instance.create_contact(create_contact) |
|
|
|
#raise Warning(api_response) |
|
|
|
_logger.info(api_response) |
|
|
@ -122,6 +130,7 @@ class MailingContact(models.Model): |
|
|
|
return True |
|
|
|
|
|
|
|
except ApiException as e: |
|
|
|
_logger.info('create_sendinblue_contact -5') |
|
|
|
_logger.info(str(e)) |
|
|
|
#raise Warning("Exception when calling ContactsApi->create_list: %s\n" % e) |
|
|
|
return False |