Skip to content

Commit b5f12d2

Browse files
Big-LoloCopilot
andauthored
Update src/impl/Event/service.py
Co-authored-by: Copilot <[email protected]>
1 parent b754750 commit b5f12d2

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

src/impl/Event/service.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,42 +1017,48 @@ def send_reminder_mails(
10171017
hackers = event.accepted_hackers
10181018

10191019
for hacker in hackers:
1020-
reg = (
1021-
db.session.query(HackerRegistration)
1022-
.filter(
1023-
HackerRegistration.user_id == hacker.id,
1024-
HackerRegistration.event_id == event.id,
1025-
)
1026-
.first()
1027-
)
1028-
# send reminder only if registration exists and assistance not confirmed
1029-
if reg is None or reg.confirmed_assistance:
1030-
continue
1031-
1032-
# ensure there is a confirmation token for this registration
1033-
if not reg.confirm_assistance_token:
1034-
reg.confirm_assistance_token = AssistenceToken(hacker, event.id).to_token()
1035-
1036-
# compute days left until event (rounded down)
10371020
try:
1038-
delta = event.start_date - datetime.now()
1039-
days_left = max(0, int(delta.total_seconds() // 86400))
1040-
except Exception:
1041-
days_left = 0
1042-
1043-
fields = f"{hacker.name},{event.name},{days_left},{reg.confirm_assistance_token}"
1044-
1045-
mail = self.mail_client.create_mail(
1046-
MailCreate(
1047-
template_id=self.mail_client.get_internall_template_id(
1048-
InternalTemplate.EVENT_HACKER_REMINDER
1049-
),
1050-
subject=f"{event.name} - Recordatori de confirmació d'assistència",
1051-
receiver_id=str(hacker.id),
1052-
receiver_mail=str(hacker.email),
1053-
fields=fields,
1021+
reg = (
1022+
db.session.query(HackerRegistration)
1023+
.filter(
1024+
HackerRegistration.user_id == hacker.id,
1025+
HackerRegistration.event_id == event.id,
1026+
)
1027+
.first()
10541028
)
1055-
)
1056-
# send the created mail
1057-
self.mail_client.send_mail_by_id(mail.id)
1058-
db.session.commit()
1029+
# send reminder only if registration exists and assistance not confirmed
1030+
if reg is None or reg.confirmed_assistance:
1031+
continue
1032+
1033+
# ensure there is a confirmation token for this registration
1034+
if not reg.confirm_assistance_token:
1035+
reg.confirm_assistance_token = AssistenceToken(hacker, event.id).to_token()
1036+
1037+
# compute days left until event (rounded down)
1038+
try:
1039+
delta = event.start_date - datetime.now()
1040+
days_left = max(0, int(delta.total_seconds() // 86400))
1041+
except Exception:
1042+
days_left = 0
1043+
1044+
fields = f"{hacker.name},{event.name},{days_left},{reg.confirm_assistance_token}"
1045+
1046+
mail = self.mail_client.create_mail(
1047+
MailCreate(
1048+
template_id=self.mail_client.get_internall_template_id(
1049+
InternalTemplate.EVENT_HACKER_REMINDER
1050+
),
1051+
subject=f"{event.name} - Recordatori de confirmació d'assistència",
1052+
receiver_id=str(hacker.id),
1053+
receiver_mail=str(hacker.email),
1054+
fields=fields,
1055+
)
1056+
)
1057+
# send the created mail
1058+
self.mail_client.send_mail_by_id(mail.id)
1059+
db.session.commit()
1060+
except Exception as e:
1061+
db.session.rollback()
1062+
# Optionally log the error here, e.g.:
1063+
# print(f"Failed to send reminder to hacker {hacker.id}: {e}")
1064+
continue

0 commit comments

Comments
 (0)