Skip to content

Commit

Permalink
Send user_id
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 27, 2024
1 parent fb2d96b commit 6b14aff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 12 additions & 5 deletions lemarche/www/tenders/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}&not_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(),
Expand All @@ -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}&not_interested=True",
"TENDER_URL": tender_url,
"TENDER_NOT_INTERESTED_URL": tender_not_interested_url,
}

api_mailjet.send_transactional_email_with_template(
Expand Down
12 changes: 9 additions & 3 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6b14aff

Please sign in to comment.