Skip to content

Commit

Permalink
Tenders: configure author transactioned question email
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jul 16, 2024
1 parent 35dbb72 commit cfe6762
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
5 changes: 0 additions & 5 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@
MAILJET_TENDERS_AUTHOR_SIAE_INTERESTED_5_MORE_TEMPLATE_ID = env.int(
"MAILJET_TENDERS_AUTHOR_SIAE_INTERESTED_5_MORE_TEMPLATE_ID", 3867200
)
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")
Expand Down
16 changes: 7 additions & 9 deletions lemarche/www/tenders/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,21 +521,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 @@ -548,21 +548,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

0 comments on commit cfe6762

Please sign in to comment.