Víðir Valberg Guðmundsson
cf99c3f40e
All checks were successful
continuous-integration/drone/push Build is passing
31 lines
785 B
Python
31 lines
785 B
Python
from django.contrib.auth.models import User
|
|
|
|
from membership.models import Membership
|
|
from membership.models import SubscriptionPeriod
|
|
|
|
|
|
def get_subscription_periods() -> list[SubscriptionPeriod]:
|
|
subscription_periods = SubscriptionPeriod.objects.prefetch_related(
|
|
"membership_set",
|
|
"membership_set__user",
|
|
).all()
|
|
return list(subscription_periods)
|
|
|
|
|
|
def get_memberships(
|
|
*, user: User | None = None, period: SubscriptionPeriod | None = None
|
|
) -> Membership.QuerySet:
|
|
memberships = Membership.objects.select_related("membership_type").all()
|
|
|
|
if user:
|
|
memberships = memberships.for_user(user)
|
|
|
|
if period:
|
|
memberships = memberships.filter(period=period)
|
|
|
|
return memberships
|
|
|
|
|
|
def get_users():
|
|
return User.objects.all()
|