Compare commits
No commits in common. "1aa0bd60140c2d363791c6d120a3564eb25c2e32" and "9341bcba0e81abba6e4e783cf05123616a77df44" have entirely different histories.
1aa0bd6014
...
9341bcba0e
@ -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 Exists, OuterRef
|
from django.db.models import Q, Count, BooleanField
|
||||||
|
|
||||||
|
|
||||||
class Flag(models.Model):
|
class Flag(models.Model):
|
||||||
@ -21,17 +21,14 @@ 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 Exists(Flag.objects.filter(
|
return Count(
|
||||||
type=flag_type,
|
"uid",
|
||||||
name=flag_name,
|
filter=Q(flags__name=flag_name, flags__type=flag_type),
|
||||||
members=OuterRef("pk")
|
output_field=BooleanField(),
|
||||||
))
|
)
|
||||||
|
|
||||||
# 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,21 +98,6 @@ 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