From 9fb6eb85c9f4bb64c4f5bf790d46e4fcc15a27e1 Mon Sep 17 00:00:00 2001 From: aviupadhyayula Date: Thu, 26 Sep 2024 01:47:17 -0400 Subject: [PATCH] Use Club.get_officer_emails() to send alerts --- 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"),)