Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Emails): Besoins : configurer les envois d'e-mails "avez-vous transactionné ?" avec TemplateTransactional (3/X) #1343

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +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
MAILJET_TENDERS_SIAE_TRANSACTIONED_QUESTION_7D_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_SIAE_TRANSACTIONED_QUESTION_7D_TEMPLATE_ID", 5207266
)


# -- Sendinblue (Brevo)
BREVO_API_KEY = env.str("BREVO_API_KEY", "set-it")
Expand Down
31 changes: 13 additions & 18 deletions lemarche/www/tenders/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,21 +515,21 @@ 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 = {
"TENDER_AUTHOR_FIRST_NAME": tender.author.first_name,
"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()}"
Expand All @@ -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(),
}
Expand Down Expand Up @@ -587,18 +585,17 @@ def send_tenders_siaes_survey(tender: Tender, kind="transactioned_question_7d"):


def send_tenders_siae_survey(tendersiae: TenderSiae, kind="transactioned_question_7d"):
email_subject = f"Suite à notre demande de {tendersiae.tender.title}"
template_id = settings.MAILJET_TENDERS_SIAE_TRANSACTIONED_QUESTION_7D_TEMPLATE_ID
email_template = TemplateTransactional.objects.get(code="TENDERS_SIAE_TRANSACTIONED_QUESTION_7D")

for user in tendersiae.siae.users.all():
recipient_list = whitelist_recipient_list([user.email])
if recipient_list:
recipient_email = recipient_list[0] if recipient_list else ""
if len(recipient_list):
recipient_email = recipient_list[0]
recipient_name = user.full_name

variables = {
"TENDER_AUTHOR_FULL_NAME": tendersiae.tender.contact_full_name,
"tender_author_company": tendersiae.tender.author.company_name,
"TENDER_AUTHOR_COMPANY": tendersiae.tender.author.company_name,
"TENDER_TITLE": tendersiae.tender.title,
"TENDER_VALIDATE_AT": tendersiae.tender.first_sent_at.strftime("%d %B %Y"), # TODO: TENDER_SENT_AT?
"TENDER_KIND": tendersiae.tender.get_kind_display(),
Expand All @@ -615,21 +612,19 @@ def send_tenders_siae_survey(tendersiae: TenderSiae, kind="transactioned_questio
variables["ANSWER_YES_URL"] = answer_url_with_sesame_token + "&answer=True"
variables["ANSWER_NO_URL"] = answer_url_with_sesame_token + "&answer=False"

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,
)

# update tendersiae
tendersiae.survey_transactioned_send_date = timezone.now()
# 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(),
}
Expand Down
Loading