membershipworks: Fix is_active
check by using aggregation
This commit is contained in:
parent
60bbe18322
commit
9a2915b247
@ -1,5 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q, Count, BooleanField
|
||||||
|
|
||||||
|
|
||||||
class Flag(models.Model):
|
class Flag(models.Model):
|
||||||
@ -137,15 +137,19 @@ class Member(models.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def with_is_active(cls):
|
def with_is_active(cls):
|
||||||
return cls.objects.annotate(
|
def has_flag(flag_type: str, flag_name: str):
|
||||||
is_active=(
|
return Count(
|
||||||
Q(flags__name="Members", flags__type="folder")
|
"uid",
|
||||||
| Q(flags__name="CMS Staff", flags__type="folder")
|
filter=Q(flags__name=flag_name, flags__type=flag_type),
|
||||||
|
output_field=BooleanField(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return cls.objects.annotate(
|
||||||
|
is_active=(has_flag("folder", "Members") | has_flag("folder", "CMS Staff"))
|
||||||
& ~(
|
& ~(
|
||||||
Q(flags__name="Account On Hold", flags__type="label")
|
has_flag("label", "Account On Hold")
|
||||||
| Q(flags__name="CMS Membership on hold", flags__type="level")
|
| has_flag("level", "CMS Membership on hold")
|
||||||
| Q(flags__name="Former Members", flags__type="folder")
|
| has_flag("folder", "Former Members")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user