diff --git a/config/settings/base.py b/config/settings/base.py index ae33c1e4f..b0c83d67c 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -332,12 +332,6 @@ # Transactional email templates # -- tender: siae & partners MAILJET_TENDERS_PARTNER_PRESENTATION_TEMPLATE_ID = env.int("MAILJET_TENDERS_PARTNER_PRESENTATION_TEMPLATE_ID", 3868179) -# -- tender: author -MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID = env.int("MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID", 4017446) -MAILJET_TENDERS_AUTHOR_TRANSACTIONED_QUESTION_7D_TEMPLATE_ID = env.int( - "MAILJET_TENDERS_AUTHOR_TRANSACTIONED_QUESTION_7D_TEMPLATE_ID", 5207181 -) # 4951625 - # -- Sendinblue (Brevo) BREVO_API_KEY = env.str("BREVO_API_KEY", "set-it") diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index cb561f62d..4b43633ab 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -515,10 +515,9 @@ def notify_admin_tender_created(tender: Tender): def send_tenders_author_feedback_or_survey(tender: Tender, kind="feedback_30d"): - email_subject = f"Suite à votre {tender.get_kind_display().lower()}" recipient_list = whitelist_recipient_list([tender.author.email]) - if recipient_list and not tender.contact_notifications_disabled: - recipient_email = recipient_list[0] if recipient_list else "" + if len(recipient_list) and not tender.contact_notifications_disabled: + recipient_email = recipient_list[0] recipient_name = tender.author.full_name variables = { @@ -526,10 +525,11 @@ def send_tenders_author_feedback_or_survey(tender: Tender, kind="feedback_30d"): "TENDER_TITLE": tender.title, "TENDER_VALIDATE_AT": tender.first_sent_at.strftime("%d %B %Y"), # TODO: TENDER_SENT_AT? "TENDER_KIND": tender.get_kind_display(), + "TENDER_KIND_LOWER": tender.get_kind_display().lower(), } if kind in ["transactioned_question_7d", "transactioned_question_7d_reminder"]: - template_id = settings.MAILJET_TENDERS_AUTHOR_TRANSACTIONED_QUESTION_7D_TEMPLATE_ID + email_template = TemplateTransactional.objects.get(code="TENDERS_AUTHOR_TRANSACTIONED_QUESTION_7D") user_sesame_query_string = sesame_get_query_string(tender.author) # TODO: sesame scope parameter answer_url_with_sesame_token = ( f"https://{get_domain_url()}" @@ -542,21 +542,19 @@ def send_tenders_author_feedback_or_survey(tender: Tender, kind="feedback_30d"): # add timestamp tender.survey_transactioned_send_date = timezone.now() else: - template_id = settings.MAILJET_TENDERS_AUTHOR_FEEDBACK_30D_TEMPLATE_ID + email_template = TemplateTransactional.objects.get(code="TENDERS_AUTHOR_FEEDBACK_30D") - api_mailjet.send_transactional_email_with_template( - template_id=template_id, + email_template.send_transactional_email( recipient_email=recipient_email, recipient_name=recipient_name, variables=variables, - subject=email_subject, ) # log email log_item = { "action": f"email_{kind}_sent", + "email_template": email_template.code, "email_to": recipient_email, - "email_subject": email_subject, # "email_body": email_body, "email_timestamp": timezone.now().isoformat(), }