From 9b0a051bac4ebba9e793bfca6a0264c684e018a3 Mon Sep 17 00:00:00 2001 From: "madjid.asa" Date: Wed, 21 Feb 2024 10:39:35 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20retrait=20de=20l'envoi=20de=20mail?= =?UTF-8?q?=20=C3=A0=20j+2=20aux=20auteurs=20de=20besoins=20incr=C3=A9ment?= =?UTF-8?q?aux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clevercloud/cron.json | 1 - .../tenders_send_author_incremental.sh | 22 --------- config/settings/base.py | 4 +- .../send_author_incremental_emails.py | 45 ------------------- lemarche/www/tenders/tasks.py | 34 -------------- 5 files changed, 1 insertion(+), 105 deletions(-) delete mode 100755 clevercloud/tenders_send_author_incremental.sh delete mode 100644 lemarche/tenders/management/commands/send_author_incremental_emails.py diff --git a/clevercloud/cron.json b/clevercloud/cron.json index 6cf9cc0f6..bbe267a78 100644 --- a/clevercloud/cron.json +++ b/clevercloud/cron.json @@ -17,6 +17,5 @@ "30 8 * * * $ROOT/clevercloud/tenders_send_author_transactioned_question_emails.sh", "0 9 * * * $ROOT/clevercloud/tenders_send_siae_contacted_reminder_emails.sh", "10 9 * * * $ROOT/clevercloud/tenders_send_siae_interested_reminder_emails.sh", - "20 9 * * * $ROOT/clevercloud/tenders_send_author_incremental.sh", "*/5 8-15 * * 1-5 $ROOT/clevercloud/tenders_send_validated.sh" ] \ No newline at end of file diff --git a/clevercloud/tenders_send_author_incremental.sh b/clevercloud/tenders_send_author_incremental.sh deleted file mode 100755 index ba787a3c0..000000000 --- a/clevercloud/tenders_send_author_incremental.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -l - -# Send e-mail to Tender author if incremental - -# Do not run if this env var is not set: -if [[ -z "$CRON_TENDER_SEND_AUTHOR_INCREMENTAL_ENABLED" ]]; then - echo "CRON_TENDER_SEND_AUTHOR_INCREMENTAL_ENABLED not set. Exiting..." - exit 0 -fi - -# About clever cloud cronjobs: -# https://www.clever-cloud.com/doc/tools/crons/ - -if [[ "$INSTANCE_NUMBER" != "0" ]]; then - echo "Instance number is ${INSTANCE_NUMBER}. Stop here." - exit 0 -fi - -# $APP_HOME is set by default by clever cloud. -cd $APP_HOME - -django-admin send_author_incremental_emails diff --git a/config/settings/base.py b/config/settings/base.py index 35b5adcb3..6bd8d14a4 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -9,6 +9,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ + import locale import os @@ -378,9 +379,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_INCREMENTAL_2D_TEMPLATE_ID = env.int( - "MAILJET_TENDERS_AUTHOR_INCREMENTAL_2D_TEMPLATE_ID", 4585824 -) 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 diff --git a/lemarche/tenders/management/commands/send_author_incremental_emails.py b/lemarche/tenders/management/commands/send_author_incremental_emails.py deleted file mode 100644 index 3451a4be3..000000000 --- a/lemarche/tenders/management/commands/send_author_incremental_emails.py +++ /dev/null @@ -1,45 +0,0 @@ -from datetime import timedelta - -from django.core.management.base import BaseCommand -from django.utils import timezone - -from lemarche.tenders.models import Tender -from lemarche.www.tenders.tasks import send_author_incremental_2_days_email - - -class Command(BaseCommand): - """ - Daily script to check recently sent Tenders. If incremental, then contact author - When? J+2 - - Usage: - python manage.py send_author_incremental_emails --dry-run - python manage.py send_author_incremental_emails - """ - - def add_arguments(self, parser): - parser.add_argument("--dry-run", dest="dry_run", action="store_true", help="Dry run, no sends") - - def handle(self, dry_run=False, **options): - self.stdout.write("-" * 80) - self.stdout.write("Script to send Tender incremental emails...") - - self.stdout.write("-" * 80) - self.stdout.write("Step 1: Find Tender sent J+2") - two_days_ago = timezone.now() - timedelta(days=2) - three_days_ago = timezone.now() - timedelta(days=3) - tender_sent_incremental = Tender.objects.sent().is_incremental() - tender_sent_incremental_2_days = tender_sent_incremental.filter(first_sent_at__gte=three_days_ago).filter( - first_sent_at__lt=two_days_ago - ) - self.stdout.write(f"Found {tender_sent_incremental_2_days.count()} Tenders") - - if not dry_run: - self.stdout.write("-" * 80) - self.stdout.write("Step 2: Send emails") - for tender in tender_sent_incremental_2_days: - send_author_incremental_2_days_email(tender) - self.stdout.write(f"Sent {tender_sent_incremental_2_days.count()} J+2 emails") - - self.stdout.write("-" * 80) - self.stdout.write("Done!") diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index 85c1982aa..a8dce9285 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -507,40 +507,6 @@ def notify_admin_tender_created(tender: Tender): api_slack.send_message_to_channel(text=email_body, service_id=settings.SLACK_WEBHOOK_C4_TENDER_CHANNEL) -def send_author_incremental_2_days_email(tender: Tender): - email_subject = f"Concernant votre {tender.get_kind_display()} sur le Marché de l'inclusion" - 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 "" - 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(), - } - - api_mailjet.send_transactional_email_with_template( - template_id=settings.MAILJET_TENDERS_AUTHOR_INCREMENTAL_2D_TEMPLATE_ID, - subject=email_subject, - recipient_email=recipient_email, - recipient_name=recipient_name, - variables=variables, - ) - - # log email - log_item = { - "action": "email_incremental_2d_sent", - "email_to": recipient_email, - "email_subject": email_subject, - # "email_body": email_body, - "email_timestamp": timezone.now().isoformat(), - } - tender.logs.append(log_item) - tender.save() - - 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])