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
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.db.models import Exists, OuterRef
|
||||
from django.db.models import Q, Count, BooleanField
|
||||
|
||||
|
||||
class Flag(models.Model):
|
||||
@ -21,17 +21,14 @@ class Flag(models.Model):
|
||||
|
||||
|
||||
class MemberQuerySet(models.QuerySet):
|
||||
# TODO: maybe rename to reflect EXISTS?
|
||||
@staticmethod
|
||||
def has_flag(flag_type: str, flag_name: str):
|
||||
return Exists(Flag.objects.filter(
|
||||
type=flag_type,
|
||||
name=flag_name,
|
||||
members=OuterRef("pk")
|
||||
))
|
||||
return Count(
|
||||
"uid",
|
||||
filter=Q(flags__name=flag_name, flags__type=flag_type),
|
||||
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):
|
||||
return self.annotate(
|
||||
is_active=(
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django.db.models import Prefetch
|
||||
from rest_framework import routers, serializers, viewsets
|
||||
from django.db.models import Prefetch, Q
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
@ -59,10 +59,10 @@ class DepartmentViewSet(viewsets.ModelViewSet):
|
||||
lists[department.list_name] = {
|
||||
"config": {
|
||||
"real_name": department.list_name,
|
||||
"moderator": moderator_emails,
|
||||
"subject_prefix": f"[CMS {department.name}] ",
|
||||
"reply_to_address": department.list_reply_to_address,
|
||||
},
|
||||
"moderators": moderator_emails,
|
||||
"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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user