2024-05-10 23:15:29 +08:00
|
|
|
from celery import shared_task
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def get_paying_users():
|
|
|
|
from subscriptions.models import UserSubscription
|
2024-10-30 22:09:58 +08:00
|
|
|
|
2024-05-10 23:15:29 +08:00
|
|
|
# Get a list of user subscriptions
|
2024-10-30 22:09:58 +08:00
|
|
|
active_subscriptions = UserSubscription.objects.filter(valid=True).distinct("user")
|
2024-05-10 23:15:29 +08:00
|
|
|
|
|
|
|
# Get paying users
|
|
|
|
active_users = []
|
|
|
|
|
|
|
|
# Paying regular users
|
|
|
|
active_users += [
|
2024-10-30 22:09:58 +08:00
|
|
|
subscription.user.id
|
|
|
|
for subscription in active_subscriptions
|
|
|
|
if subscription.user is not None and subscription.user.user_group is None
|
|
|
|
]
|
2024-05-10 23:15:29 +08:00
|
|
|
|
|
|
|
# Paying users within groups
|
|
|
|
active_users += [
|
2024-10-30 22:09:58 +08:00
|
|
|
subscription.user_group.members
|
|
|
|
for subscription in active_subscriptions
|
|
|
|
if subscription.user_group is not None and subscription.user is None
|
|
|
|
]
|
2024-05-10 23:15:29 +08:00
|
|
|
|
|
|
|
# Return paying users
|
|
|
|
return active_users
|