Unverified Commit afa9ea75 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Clarify some docs

parent c0e270d7
...@@ -33,6 +33,7 @@ class ActiveMemberManager(MemberManager): ...@@ -33,6 +33,7 @@ class ActiveMemberManager(MemberManager):
"""Get all active members, i.e. who have a committee membership""" """Get all active members, i.e. who have a committee membership"""
def get_queryset(self): def get_queryset(self):
"""Select all committee members"""
active_memberships = (CommitteeMembership active_memberships = (CommitteeMembership
.active_memberships .active_memberships
.exclude(committee__board__is_board=True)) .exclude(committee__board__is_board=True))
...@@ -46,6 +47,9 @@ class CurrentMemberManager(MemberManager): ...@@ -46,6 +47,9 @@ class CurrentMemberManager(MemberManager):
"""Get all members with an active membership""" """Get all members with an active membership"""
def get_queryset(self): def get_queryset(self):
"""
Select all members who have a current membership
"""
return (super().get_queryset() return (super().get_queryset()
.exclude(membership=None) .exclude(membership=None)
.filter(Q(membership__until__isnull=True) | .filter(Q(membership__until__isnull=True) |
...@@ -53,6 +57,18 @@ class CurrentMemberManager(MemberManager): ...@@ -53,6 +57,18 @@ class CurrentMemberManager(MemberManager):
.distinct()) .distinct())
def with_birthdays_in_range(self, from_date, to_date): def with_birthdays_in_range(self, from_date, to_date):
"""
Select all who are currently a Thalia member and have a
birthday within the specified range
:param from_date: the start of the range (inclusive)
:param to_date: the end of the range (inclusive)
:paramtype from_date: datetime
:paramtype to_date: datetime
:return: the filtered queryset
:rtype: Queryset
"""
queryset = (self.get_queryset() queryset = (self.get_queryset()
.filter(profile__birthday__lte=to_date)) .filter(profile__birthday__lte=to_date))
...@@ -91,6 +107,12 @@ class Member(User): ...@@ -91,6 +107,12 @@ class Member(User):
@property @property
def current_membership(self): def current_membership(self):
"""
The currently active membership of the user. None if not active.
:return: the currently active membership or None
:rtype: Membership or None
"""
membership = self.latest_membership membership = self.latest_membership
if membership and not membership.is_active(): if membership and not membership.is_active():
return None return None
...@@ -98,20 +120,24 @@ class Member(User): ...@@ -98,20 +120,24 @@ class Member(User):
@property @property
def latest_membership(self): def latest_membership(self):
"""Get the most recent membership of this user"""
if not self.membership_set.exists(): if not self.membership_set.exists():
return None return None
return self.membership_set.latest('since') return self.membership_set.latest('since')
@property @property
def earliest_membership(self): def earliest_membership(self):
"""Get the earliest membership of this user"""
if not self.membership_set.exists(): if not self.membership_set.exists():
return None return None
return self.membership_set.earliest('since') return self.membership_set.earliest('since')
def has_been_member(self): def has_been_member(self):
"""Has this user ever been a member?"""
return self.membership_set.filter(type='member').count() > 0 return self.membership_set.filter(type='member').count() > 0
def has_been_honorary_member(self): def has_been_honorary_member(self):
"""Has this user ever been an honorary member?"""
return self.membership_set.filter(type='honorary').count() > 0 return self.membership_set.filter(type='honorary').count() > 0
def has_active_membership(self): def has_active_membership(self):
...@@ -128,12 +154,20 @@ class Member(User): ...@@ -128,12 +154,20 @@ class Member(User):
@classmethod @classmethod
def all_with_membership(cls, membership_type): def all_with_membership(cls, membership_type):
"""
Get all users who have a specific membership.
:param membership_type: The membership to select by
:return: List of users
:rtype: [Member]
"""
return [x for x in cls.objects.all() return [x for x in cls.objects.all()
if x.current_membership and if x.current_membership and
x.current_membership.type == membership_type] x.current_membership.type == membership_type]
@property @property
def can_attend_events(self): def can_attend_events(self):
"""May this user attend events"""
if not self.profile: if not self.profile:
return False return False
...@@ -142,6 +176,7 @@ class Member(User): ...@@ -142,6 +176,7 @@ class Member(User):
self.current_membership is not None) self.current_membership is not None)
def get_committees(self): def get_committees(self):
"""Get the committees this user is a member of"""
return Committee.unfiltered_objects.filter( return Committee.unfiltered_objects.filter(
Q(committeemembership__member=self) & Q(committeemembership__member=self) &
( (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment