From 6b14aff14fa7b1f64af563c6ca70288a964dd099 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 27 Mar 2024 11:31:29 +0100 Subject: [PATCH] Send user_id --- lemarche/www/tenders/tasks.py | 17 ++++++++++++----- lemarche/www/tenders/views.py | 12 +++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index 38dc11890..bcba191d1 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -9,6 +9,7 @@ from lemarche.siaes.models import Siae from lemarche.tenders.models import PartnerShareTender, Tender, TenderSiae +from lemarche.users.models import User from lemarche.utils.apis import api_hubspot, api_mailjet, api_slack from lemarche.utils.data import date_to_string from lemarche.utils.emails import send_mail_async, whitelist_recipient_list @@ -79,7 +80,7 @@ def send_tender_emails_to_siaes(tender: Tender): for user in siae.users.all(): siae_users_count += 1 if user.email != siae.contact_email: - send_tender_email_to_siae(tender, siae, email_subject, email_to_override=user.email) + send_tender_email_to_siae(tender, siae, email_subject, recipient_to_override=user) siae_users_send_count += 1 TenderSiae.objects.filter(tender=tender, siae__in=siaes).update( email_send_date=timezone.now(), updated_at=timezone.now() @@ -170,14 +171,20 @@ def send_tender_email_to_partner(email_subject: str, tender: Tender, partner: Pa # @task() -def send_tender_email_to_siae(tender: Tender, siae: Siae, email_subject: str, email_to_override=None): +def send_tender_email_to_siae(tender: Tender, siae: Siae, email_subject: str, recipient_to_override: User = None): # override siae.contact_email if email_to_override is provided - email_to = email_to_override or siae.contact_email + email_to = recipient_to_override.email if recipient_to_override else siae.contact_email recipient_list = whitelist_recipient_list([email_to]) if recipient_list: recipient_email = recipient_list[0] if recipient_list else "" recipient_name = siae.contact_full_name + tender_url = f"{get_object_share_url(tender)}?siae_id={siae.id}" + tender_not_interested_url = f"{get_object_share_url(tender)}?siae_id={siae.id}¬_interested=True" + if recipient_to_override: + tender_url += f"&user_id={recipient_to_override.id}" + tender_not_interested_url += f"&user_id={recipient_to_override.id}" + variables = { "SIAE_CONTACT_FIRST_NAME": siae.contact_first_name, "SIAE_SECTORS": siae.sectors_list_string(), @@ -189,8 +196,8 @@ def send_tender_email_to_siae(tender: Tender, siae: Siae, email_subject: str, em "TENDER_PERIMETERS": tender.location_display, "TENDER_AMOUNT": tender.amount_display, "TENDER_DEADLINE_DATE": date_to_string(tender.deadline_date), - "TENDER_URL": f"{get_object_share_url(tender)}?siae_id={siae.id}", - "TENDER_NOT_INTERESTED_URL": f"{get_object_share_url(tender)}?siae_id={siae.id}¬_interested=True", + "TENDER_URL": tender_url, + "TENDER_NOT_INTERESTED_URL": tender_not_interested_url, } api_mailjet.send_transactional_email_with_template( diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 2dd2a0a16..1a7c06023 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -344,11 +344,17 @@ def get(self, request, *args, **kwargs): self.object = self.get_object() user = self.request.user self.siae_id = request.GET.get("siae_id", None) + self.user_id = request.GET.get("user_id", None) # update 'email_link_click_date' if self.siae_id: - TenderSiae.objects.filter(tender=self.object, siae_id=self.siae_id, email_link_click_date=None).update( - email_link_click_date=timezone.now(), updated_at=timezone.now() - ) + if self.user_id: + TenderSiae.objects.filter(tender=self.object, siae_id=self.siae_id, email_link_click_date=None).update( + user_id=self.user_id, email_link_click_date=timezone.now(), updated_at=timezone.now() + ) + else: + TenderSiae.objects.filter(tender=self.object, siae_id=self.siae_id, email_link_click_date=None).update( + email_link_click_date=timezone.now(), updated_at=timezone.now() + ) # update 'detail_display_date' if user.is_authenticated: if user.kind == User.KIND_SIAE: