From 308fc0b133dc1878a8496c40410ce00b936996a7 Mon Sep 17 00:00:00 2001 From: Avi Upadhyayula <69180850+aviupadhyayula@users.noreply.github.com> Date: Fri, 27 Sep 2024 19:29:26 -0400 Subject: [PATCH] Use Club.get_officer_emails() to send alerts (#729) --- backend/clubs/models.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/backend/clubs/models.py b/backend/clubs/models.py index d75e1ab02..bb95fcedc 100644 --- a/backend/clubs/models.py +++ b/backend/clubs/models.py @@ -782,11 +782,7 @@ def __str__(self): def send_question_mail(self, request=None): domain = get_domain(request) - owner_emails = list( - self.club.membership_set.filter( - role__lte=Membership.ROLE_OFFICER, active=True - ).values_list("person__email", flat=True) - ) + emails = self.club.get_officer_emails() context = { "name": self.club.name, @@ -794,11 +790,11 @@ def send_question_mail(self, request=None): "url": settings.QUESTION_URL.format(domain=domain, club=self.club.code), } - if owner_emails: + if emails: send_mail_helper( name="question", subject="Question for {}".format(self.club.name), - emails=owner_emails, + emails=emails, context=context, ) @@ -1114,20 +1110,17 @@ def send_request(self, request=None): "full_name": self.person.get_full_name(), } - owner_emails = list( - self.club.membership_set.filter( - role__lte=Membership.ROLE_OFFICER, active=True - ).values_list("person__email", flat=True) - ) + emails = self.club.get_officer_emails() - send_mail_helper( - name="request", - subject="Membership Request from {} for {}".format( - self.person.get_full_name(), self.club.name - ), - emails=owner_emails, - context=context, - ) + if emails: + send_mail_helper( + name="request", + subject="Membership Request from {} for {}".format( + self.person.get_full_name(), self.club.name + ), + emails=emails, + context=context, + ) class Meta: unique_together = (("person", "club"),)