From d5a45a0589e8f9e3b8e95bce4c87b0ed9804977f Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 2 Feb 2023 21:35:27 -0500 Subject: [PATCH] paperwork: Use Volunteer Email field for shop leads in mailing lists --- membershipworks/models.py | 9 +++++++-- paperwork/api.py | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/membershipworks/models.py b/membershipworks/models.py index e5a5bdc..6a43387 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -52,6 +52,7 @@ class Member(models.Model): last_name = models.TextField(db_column="Last Name", null=True) phone = models.TextField(db_column="Phone", null=True) email = models.TextField(db_column="Email", null=True) + volunteer_email = models.TextField(db_column="Volunteer Email", null=True) address_street = models.TextField(db_column="Address (Street)", null=True) address_city = models.TextField(db_column="Address (City)", null=True) address_state_province = models.TextField( @@ -163,9 +164,13 @@ class Member(models.Model): db_table = "members" ordering = ("first_name", "last_name") - def sanitized_mailbox(self, name_ext: str = ""): + def sanitized_mailbox(self, name_ext: str = "", use_volunteer=False): + if use_volunteer and self.volunteer_email: + email = self.volunteer_email + else: + email = self.email return django.core.mail.message.sanitize_address( - (self.account_name + name_ext, self.email), settings.DEFAULT_CHARSET + (self.account_name + name_ext, email), settings.DEFAULT_CHARSET ) diff --git a/paperwork/api.py b/paperwork/api.py index 6369170..ce84772 100644 --- a/paperwork/api.py +++ b/paperwork/api.py @@ -40,7 +40,8 @@ class DepartmentViewSet(viewsets.ModelViewSet): for department in departments.filter(has_mailing_list=True): if department.shop_lead_flag is not None: moderator_emails = { - member.email for member in department.shop_lead_flag.members.all() + member.volunteer_email if member.volunteer_email else member.email + for member in department.shop_lead_flag.members.all() } else: moderator_emails = [] @@ -90,7 +91,8 @@ class DepartmentViewSet(viewsets.ModelViewSet): lists["ShopLeads"] = { "members": { shoplead.sanitized_mailbox( - f" - {'/'.join(department.name for department in departments)}" + f" - {'/'.join(department.name for department in departments)}", + use_volunteer=True, ) for shoplead, departments in shopleads.items() },