paperwork: Rename Department.list_moderator_flag to shop_lead_flag

This commit is contained in:
Adam Goldsmith 2023-01-23 21:06:06 -05:00
parent 8556190117
commit 3acfaaa19f
4 changed files with 40 additions and 8 deletions

View File

@ -22,7 +22,7 @@ class Department(admin.ModelAdmin):
"name", "name",
"parent", "parent",
"has_mailing_list", "has_mailing_list",
"list_moderator_flag", "shop_lead_flag",
"list_reply_to_address", "list_reply_to_address",
] ]

View File

@ -15,7 +15,7 @@ from .models import (
class DepartmentSerializer(serializers.HyperlinkedModelSerializer): class DepartmentSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Department model = Department
fields = ["name", "parent", "list_moderator_flag", "list_reply_to_address"] fields = ["name", "parent", "shop_lead_flag", "list_reply_to_address"]
class DepartmentViewSet(viewsets.ModelViewSet): class DepartmentViewSet(viewsets.ModelViewSet):
@ -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__members", "shop_lead_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(),
@ -38,10 +38,9 @@ class DepartmentViewSet(viewsets.ModelViewSet):
) )
lists = {} lists = {}
for department in departments: for department in departments:
if department.list_moderator_flag is not None: if department.shop_lead_flag is not None:
moderator_emails = { moderator_emails = {
member.email member.email for member in department.shop_lead_flag.members.all()
for member in department.list_moderator_flag.members.all()
} }
else: else:
moderator_emails = [] moderator_emails = []
@ -82,7 +81,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
shopleads = {} shopleads = {}
for department in departments: for department in departments:
for member in department.list_moderator_flag.members.all(): for member in department.shop_lead_flag.members.all():
if member not in shopleads: if member not in shopleads:
shopleads[member] = [] shopleads[member] = []
shopleads[member].append(department) shopleads[member].append(department)

View File

@ -0,0 +1,32 @@
# Generated by Django 4.1.3 on 2023-01-24 02:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("membershipworks", "0002_alter_flag_options"),
("paperwork", "0008_remove_certificationdefinition_mailing_list"),
]
operations = [
migrations.RenameField(
model_name="department",
old_name="list_moderator_flag",
new_name="shop_lead_flag",
),
migrations.AlterField(
model_name="department",
name="shop_lead_flag",
field=models.ForeignKey(
blank=True,
db_constraint=False,
help_text="This will also be used to set the moderators for the mailing list",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="membershipworks.flag",
),
),
]

View File

@ -60,12 +60,13 @@ class Department(models.Model):
"self", on_delete=models.PROTECT, related_name="children", blank=True, null=True "self", on_delete=models.PROTECT, related_name="children", blank=True, null=True
) )
has_mailing_list = models.BooleanField(default=False) has_mailing_list = models.BooleanField(default=False)
list_moderator_flag = models.ForeignKey( shop_lead_flag = models.ForeignKey(
MembershipWorksFlag, MembershipWorksFlag,
on_delete=models.PROTECT, on_delete=models.PROTECT,
blank=True, blank=True,
null=True, null=True,
db_constraint=False, db_constraint=False,
help_text="This will also be used to set the moderators for the mailing list",
) )
list_reply_to_address = models.EmailField(max_length=254, blank=True) list_reply_to_address = models.EmailField(max_length=254, blank=True)