paperwork: Use Volunteer Email field for shop leads in mailing lists

This commit is contained in:
Adam Goldsmith 2023-02-02 21:35:27 -05:00
parent b4d100478e
commit d5a45a0589
2 changed files with 11 additions and 4 deletions

View File

@ -52,6 +52,7 @@ class Member(models.Model):
last_name = models.TextField(db_column="Last Name", null=True) last_name = models.TextField(db_column="Last Name", null=True)
phone = models.TextField(db_column="Phone", null=True) phone = models.TextField(db_column="Phone", null=True)
email = models.TextField(db_column="Email", 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_street = models.TextField(db_column="Address (Street)", null=True)
address_city = models.TextField(db_column="Address (City)", null=True) address_city = models.TextField(db_column="Address (City)", null=True)
address_state_province = models.TextField( address_state_province = models.TextField(
@ -163,9 +164,13 @@ class Member(models.Model):
db_table = "members" db_table = "members"
ordering = ("first_name", "last_name") 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( 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
) )

View File

@ -40,7 +40,8 @@ class DepartmentViewSet(viewsets.ModelViewSet):
for department in departments.filter(has_mailing_list=True): for department in departments.filter(has_mailing_list=True):
if department.shop_lead_flag is not None: if department.shop_lead_flag is not None:
moderator_emails = { 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: else:
moderator_emails = [] moderator_emails = []
@ -90,7 +91,8 @@ class DepartmentViewSet(viewsets.ModelViewSet):
lists["ShopLeads"] = { lists["ShopLeads"] = {
"members": { "members": {
shoplead.sanitized_mailbox( 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() for shoplead, departments in shopleads.items()
}, },