paperwork: Allow exempting departments from having a mailing list

This commit is contained in:
Adam Goldsmith 2023-01-19 16:02:17 -05:00
parent ca43798ce6
commit 74bbbb713e
4 changed files with 27 additions and 2 deletions

View File

@ -18,7 +18,13 @@ from .certification_emails import all_certification_emails
@admin.register(Department)
class Department(admin.ModelAdmin):
search_fields = ["name"]
list_display = ["name", "parent", "list_moderator_flag", "list_reply_to_address"]
list_display = [
"name",
"parent",
"has_mailing_list",
"list_moderator_flag",
"list_reply_to_address",
]
class CertificationVersionInline(admin.TabularInline):

View File

@ -28,7 +28,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
Generate a mailing list for each department, containing all
certified users for tools in that department or child departments
"""
departments = self.queryset.prefetch_related(
departments = self.queryset.filter(has_mailing_list=True).prefetch_related(
"children",
"list_moderator_flag",
Prefetch(

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.3 on 2023-01-19 21:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("paperwork", "0006_department_alter_certificationdefinition_department"),
]
operations = [
migrations.AddField(
model_name="department",
name="has_mailing_list",
field=models.BooleanField(default=False),
),
]

View File

@ -59,6 +59,7 @@ class Department(models.Model):
parent = models.ForeignKey(
"self", on_delete=models.PROTECT, related_name="children", blank=True, null=True
)
has_mailing_list = models.BooleanField(default=False)
list_moderator_flag = models.ForeignKey(
MembershipWorksFlag,
on_delete=models.PROTECT,