Compare commits
3 Commits
9341bcba0e
...
1aa0bd6014
Author | SHA1 | Date | |
---|---|---|---|
1aa0bd6014 | |||
a3a8c305ac | |||
a51f246667 |
@ -3,7 +3,7 @@ from typing import Optional
|
|||||||
import django.core.mail.message
|
import django.core.mail.message
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q, Count, BooleanField
|
from django.db.models import Exists, OuterRef
|
||||||
|
|
||||||
|
|
||||||
class Flag(models.Model):
|
class Flag(models.Model):
|
||||||
@ -21,14 +21,17 @@ class Flag(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class MemberQuerySet(models.QuerySet):
|
class MemberQuerySet(models.QuerySet):
|
||||||
|
# TODO: maybe rename to reflect EXISTS?
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def has_flag(flag_type: str, flag_name: str):
|
def has_flag(flag_type: str, flag_name: str):
|
||||||
return Count(
|
return Exists(Flag.objects.filter(
|
||||||
"uid",
|
type=flag_type,
|
||||||
filter=Q(flags__name=flag_name, flags__type=flag_type),
|
name=flag_name,
|
||||||
output_field=BooleanField(),
|
members=OuterRef("pk")
|
||||||
)
|
))
|
||||||
|
|
||||||
|
# TODO: it should be fairly easy to reduce the number of EXISTS by
|
||||||
|
# merging the ORed flags
|
||||||
def with_is_active(self):
|
def with_is_active(self):
|
||||||
return self.annotate(
|
return self.annotate(
|
||||||
is_active=(
|
is_active=(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from django.db.models import Prefetch
|
|
||||||
from rest_framework import routers, serializers, viewsets
|
from rest_framework import routers, serializers, viewsets
|
||||||
|
from django.db.models import Prefetch, Q
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
@ -59,10 +59,10 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
|||||||
lists[department.list_name] = {
|
lists[department.list_name] = {
|
||||||
"config": {
|
"config": {
|
||||||
"real_name": department.list_name,
|
"real_name": department.list_name,
|
||||||
"moderator": moderator_emails,
|
|
||||||
"subject_prefix": f"[CMS {department.name}] ",
|
"subject_prefix": f"[CMS {department.name}] ",
|
||||||
"reply_to_address": department.list_reply_to_address,
|
"reply_to_address": department.list_reply_to_address,
|
||||||
},
|
},
|
||||||
|
"moderators": moderator_emails,
|
||||||
"members": active_certified_members,
|
"members": active_certified_members,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +98,21 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: this isn't really in the domain of the `paperwork` app...
|
||||||
|
deskers = (
|
||||||
|
Member.objects.with_is_active()
|
||||||
|
.filter(is_active=True)
|
||||||
|
.filter(
|
||||||
|
Member.objects.has_flag("label", "Volunteer: Desker")
|
||||||
|
| Q(billing_method__startswith="Desker")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
lists["Deskers"] = {
|
||||||
|
"members": {
|
||||||
|
desker.sanitized_mailbox(use_volunteer=True) for desker in deskers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Response(lists)
|
return Response(lists)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user