paperwork: Also generate the ShopLeads mailing list in api
This commit is contained in:
parent
2f72bb7d51
commit
efe476b367
@ -163,10 +163,9 @@ class Member(models.Model):
|
|||||||
db_table = "members"
|
db_table = "members"
|
||||||
ordering = ("first_name", "last_name")
|
ordering = ("first_name", "last_name")
|
||||||
|
|
||||||
@property
|
def sanitized_mailbox(self, name_ext: str = ""):
|
||||||
def sanitized_mailbox(self):
|
|
||||||
return django.core.mail.message.sanitize_address(
|
return django.core.mail.message.sanitize_address(
|
||||||
(self.account_name, self.email), settings.DEFAULT_CHARSET
|
(self.account_name + name_ext, self.email), settings.DEFAULT_CHARSET
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
|||||||
"""
|
"""
|
||||||
departments = self.queryset.filter(has_mailing_list=True).prefetch_related(
|
departments = self.queryset.filter(has_mailing_list=True).prefetch_related(
|
||||||
"children",
|
"children",
|
||||||
"list_moderator_flag",
|
"list_moderator_flag__members",
|
||||||
Prefetch(
|
Prefetch(
|
||||||
"certificationdefinition_set__certificationversion_set__certification_set__member",
|
"certificationdefinition_set__certificationversion_set__certification_set__member",
|
||||||
queryset=Member.objects.with_is_active(),
|
queryset=Member.objects.with_is_active(),
|
||||||
@ -39,16 +39,17 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
|||||||
lists = {}
|
lists = {}
|
||||||
for department in departments:
|
for department in departments:
|
||||||
if department.list_moderator_flag is not None:
|
if department.list_moderator_flag is not None:
|
||||||
moderator_emails = department.list_moderator_flag.members.values_list(
|
moderator_emails = {
|
||||||
"email", flat=True
|
member.email
|
||||||
)
|
for member in department.list_moderator_flag.members.all()
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
moderator_emails = []
|
moderator_emails = []
|
||||||
|
|
||||||
# TODO: this could be done in SQL instead if
|
# TODO: this could be done in SQL instead if
|
||||||
# membershipworks was in the same database
|
# membershipworks was in the same database
|
||||||
active_certified_members = {
|
active_certified_members = {
|
||||||
member_cert.member.sanitized_mailbox
|
member_cert.member.sanitized_mailbox()
|
||||||
for certification in department.certificationdefinition_set.all()
|
for certification in department.certificationdefinition_set.all()
|
||||||
for version in certification.certificationversion_set.all()
|
for version in certification.certificationversion_set.all()
|
||||||
for member_cert in version.certification_set.all()
|
for member_cert in version.certification_set.all()
|
||||||
@ -79,6 +80,23 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
|||||||
if department.parent_id is None:
|
if department.parent_id is None:
|
||||||
recurse_children(department)
|
recurse_children(department)
|
||||||
|
|
||||||
|
shopleads = {}
|
||||||
|
for department in departments:
|
||||||
|
for member in department.list_moderator_flag.members.all():
|
||||||
|
if member not in shopleads:
|
||||||
|
shopleads[member] = []
|
||||||
|
shopleads[member].append(department)
|
||||||
|
|
||||||
|
# Add members to the Shop Leads mailing list, but don't configure it
|
||||||
|
lists["ShopLeads"] = {
|
||||||
|
"members": {
|
||||||
|
shoplead.sanitized_mailbox(
|
||||||
|
f" - {'/'.join(department.name for department in departments)}"
|
||||||
|
)
|
||||||
|
for shoplead, departments in shopleads.items()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return Response(lists)
|
return Response(lists)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user