membershipworks: Use django functions to sanitize Member mailbox

This commit is contained in:
Adam Goldsmith 2023-01-17 16:26:53 -05:00
parent aa87026e99
commit 39f97dd6f9
2 changed files with 9 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import django.core.mail.message
from django.conf import settings
from django.db import models
from django.db.models import Q, Count, BooleanField
@ -160,6 +162,12 @@ class Member(models.Model):
db_table = "members"
ordering = ("first_name", "last_name")
@property
def sanitized_mailbox(self):
return django.core.mail.message.sanitize_address(
(self.account_name, self.email), settings.DEFAULT_CHARSET
)
class MemberFlag(models.Model):
member = models.ForeignKey(Member, on_delete=models.PROTECT, db_column="uid")

View File

@ -38,7 +38,7 @@ class CertificationDefinitionViewSet(viewsets.ModelViewSet):
for cert in version.certification_set.all():
if cert.member and cert.member.is_active:
lists[definition.mailing_list].add(
f"{cert.member.account_name} <{cert.member.email}>"
cert.member.sanitized_mailbox
)
return Response(lists)