Fix player contact email handling across service methods

mailing
Razmig Sarkissian 1 month ago
parent 371bce35d7
commit 4fbfce8393
  1. 4
      tournaments/models/player_registration.py
  2. 12
      tournaments/services/email_service.py

@ -230,4 +230,6 @@ class PlayerRegistration(TournamentSubModel):
return 0
def player_contact(self):
return self.contact_email or self.email
if self.contact_email:
return self.contact_email
return self.email

@ -516,8 +516,8 @@ class TournamentEmailService:
@staticmethod
def notify(captain, other_player, tournament, message_type: TeamEmailType):
print("TournamentEmailService.notify", captain.email, captain.registered_online, tournament, message_type)
if not captain or not captain.registered_online or not captain.email:
print("TournamentEmailService.notify", captain.player_contact(), captain.registered_online, tournament, message_type)
if not captain or not captain.registered_online or not captain.player_contact():
return
tournament_details_str = tournament.build_tournament_details_str()
@ -607,7 +607,7 @@ class TournamentEmailService:
print("TournamentEmailService.notify_team 2p", team)
first_player, second_player = players
TournamentEmailService.notify(first_player, second_player, tournament, message_type)
if first_player.email != second_player.email:
if first_player.player_contact() != second_player.player_contact():
TournamentEmailService.notify(second_player, first_player, tournament, message_type)
elif len(players) == 1:
print("TournamentEmailService.notify_team 1p", team)
@ -814,11 +814,11 @@ class TournamentEmailService:
tournament_prefix_that = federal_level_category.localized_prefix_that()
processed_emails = set()
for player in player_registrations:
if not player.email or not player.registered_online:
if not player.player_contact() or not player.registered_online:
continue
if player.email in processed_emails:
if player.player_contact() in processed_emails:
continue
processed_emails.add(player.email)
processed_emails.add(player.player_contact())
tournament_details_str = tournament.build_tournament_details_str()
other_player = team_registration.get_other_player(player) if len(player_registrations) > 1 else None

Loading…
Cancel
Save