|
|
@ -50,7 +50,7 @@ class MailingContact(models.Model): |
|
|
|
|
|
|
|
@api.model |
|
|
|
def create(self, values): |
|
|
|
_logger.info('create') |
|
|
|
_logger.error('create') |
|
|
|
res = super(MailingContact, self).create(values) |
|
|
|
#ajout du contact à la liste de diffusion de sendinblue |
|
|
|
|
|
|
@ -67,7 +67,7 @@ class MailingContact(models.Model): |
|
|
|
|
|
|
|
def get_info_sendinblue_contact(self): |
|
|
|
#https://developers.sendinblue.com/reference/getfolders-1 |
|
|
|
_logger.info('get_info_sendinblue_contact') |
|
|
|
_logger.error('get_info_sendinblue_contact') |
|
|
|
f = open(SENDINBLUE_ACCOUNT_FILE) |
|
|
|
data = json.load(f) |
|
|
|
configuration = sib_api_v3_sdk.Configuration() |
|
|
@ -76,21 +76,21 @@ class MailingContact(models.Model): |
|
|
|
email = self.email |
|
|
|
|
|
|
|
try: |
|
|
|
_logger.info('get_info_sendinblue_contact -1') |
|
|
|
_logger.error('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') |
|
|
|
_logger.error('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') |
|
|
|
_logger.error('create_sendinblue_contact') |
|
|
|
if self.email and self.list_ids: |
|
|
|
_logger.info('create_sendinblue_contact -1') |
|
|
|
_logger.error('create_sendinblue_contact -1') |
|
|
|
configuration = sib_api_v3_sdk.Configuration() |
|
|
|
#https://developers.sendinblue.com/reference/getfolders-1 |
|
|
|
f = open(SENDINBLUE_ACCOUNT_FILE) |
|
|
@ -104,7 +104,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') |
|
|
|
_logger.error('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: |
|
|
@ -118,22 +118,22 @@ class MailingContact(models.Model): |
|
|
|
return True |
|
|
|
#si le contact n'existe pas dans sendinblue, on le créé |
|
|
|
else: |
|
|
|
_logger.info('create_sendinblue_contact -3') |
|
|
|
_logger.error('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') |
|
|
|
_logger.error('create_sendinblue_contact -4') |
|
|
|
api_response = api_instance.create_contact(create_contact) |
|
|
|
#raise Warning(api_response) |
|
|
|
_logger.info(api_response) |
|
|
|
_logger.error(api_response) |
|
|
|
pprint(api_response) |
|
|
|
return True |
|
|
|
|
|
|
|
except ApiException as e: |
|
|
|
_logger.info('create_sendinblue_contact -5') |
|
|
|
_logger.info(str(e)) |
|
|
|
_logger.error('create_sendinblue_contact -5') |
|
|
|
_logger.error(str(e)) |
|
|
|
#raise Warning("Exception when calling ContactsApi->create_list: %s\n" % e) |
|
|
|
return False |