Commit abf8d3ce authored by Tom van Bussel's avatar Tom van Bussel
Browse files

Rename ActiveMemberManager to CurrentMemberManager

and add a new manager for active members.
parent c7030ca1
...@@ -191,5 +191,5 @@ class RegistrationAdmin(DoNextModelAdmin): ...@@ -191,5 +191,5 @@ class RegistrationAdmin(DoNextModelAdmin):
kwargs['queryset'] = models.Event.objects.filter( kwargs['queryset'] = models.Event.objects.filter(
pk=int(request.GET['event_pk'])) pk=int(request.GET['event_pk']))
elif db_field.name == 'member': elif db_field.name == 'member':
kwargs['queryset'] = Member.active_members.all() kwargs['queryset'] = Member.current_members.all()
return super().formfield_for_foreignkey(db_field, request, **kwargs) return super().formfield_for_foreignkey(db_field, request, **kwargs)
...@@ -48,7 +48,7 @@ def get_automatic_lists(): ...@@ -48,7 +48,7 @@ def get_automatic_lists():
['commissievoorzitters', 'committeechairs'], '[THALIA] [CHAIRS]', ['commissievoorzitters', 'committeechairs'], '[THALIA] [CHAIRS]',
committee_chairs, moderated=False) committee_chairs, moderated=False)
lists += _create_automatic_list( lists += _create_automatic_list(
['optin'], '[THALIA] [OPTIN]', Member.active_members.filter( ['optin'], '[THALIA] [OPTIN]', Member.current_members.filter(
profile__receive_optin=True), profile__receive_optin=True),
multilingual=True) multilingual=True)
......
...@@ -31,7 +31,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet): ...@@ -31,7 +31,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
def get_queryset(self): def get_queryset(self):
if self.action == 'list': if self.action == 'list':
return Member.active_members.get_queryset() return Member.current_members.get_queryset()
return Member.objects.all() return Member.objects.all()
def _get_birthdays(self, member, start, end): def _get_birthdays(self, member, start, end):
...@@ -68,7 +68,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet): ...@@ -68,7 +68,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
detail='start or end query parameters invalid') from e detail='start or end query parameters invalid') from e
queryset = ( queryset = (
Member.active_members Member.current_members
.with_birthdays_in_range(start, end) .with_birthdays_in_range(start, end)
.filter(profile__show_birthday=True) .filter(profile__show_birthday=True)
) )
......
...@@ -11,7 +11,7 @@ from thaliawebsite.settings import settings ...@@ -11,7 +11,7 @@ from thaliawebsite.settings import settings
def send_membership_announcement(dry_run=False): def send_membership_announcement(dry_run=False):
members = (Member.active_members members = (Member.current_members
.filter(membership__until__isnull=True) .filter(membership__until__isnull=True)
.distinct()) .distinct())
...@@ -44,7 +44,7 @@ def send_membership_announcement(dry_run=False): ...@@ -44,7 +44,7 @@ def send_membership_announcement(dry_run=False):
def send_information_request(dry_run=False): def send_information_request(dry_run=False):
members = Member.active_members.all() members = Member.current_members.all()
with mail.get_connection() as connection: with mail.get_connection() as connection:
for member in members: for member in members:
...@@ -77,7 +77,7 @@ def send_information_request(dry_run=False): ...@@ -77,7 +77,7 @@ def send_information_request(dry_run=False):
def send_expiration_announcement(dry_run=False): def send_expiration_announcement(dry_run=False):
expiry_date = datetime.now() + timedelta(days=31) expiry_date = datetime.now() + timedelta(days=31)
members = (Member.active_members members = (Member.current_members
.filter(membership__until__lte=expiry_date) .filter(membership__until__lte=expiry_date)
.distinct()) .distinct())
......
...@@ -16,7 +16,7 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -16,7 +16,7 @@ from django.utils.translation import ugettext_lazy as _
from localflavor.generic.countries.sepa import IBAN_SEPA_COUNTRIES from localflavor.generic.countries.sepa import IBAN_SEPA_COUNTRIES
from localflavor.generic.models import IBANField from localflavor.generic.models import IBANField
from activemembers.models import Committee from activemembers.models import Committee, CommitteeMembership
class MemberManager(UserManager): class MemberManager(UserManager):
...@@ -29,6 +29,19 @@ class MemberManager(UserManager): ...@@ -29,6 +29,19 @@ class MemberManager(UserManager):
class ActiveMemberManager(MemberManager): class ActiveMemberManager(MemberManager):
"""Get all active members""" """Get all active members"""
def get_queryset(self):
active_memberships = (CommitteeMembership
.active_memberships
.exclude(committee__board__is_board=True))
return (super().get_queryset()
.filter(committeemembership__in=active_memberships)
.distinct())
class CurrentMemberManager(MemberManager):
"""Get all members with an active membership"""
def get_queryset(self): def get_queryset(self):
return (super().get_queryset() return (super().get_queryset()
.exclude(membership=None) .exclude(membership=None)
...@@ -64,6 +77,7 @@ class Member(User): ...@@ -64,6 +77,7 @@ class Member(User):
ordering = ('first_name', 'last_name') ordering = ('first_name', 'last_name')
objects = MemberManager() objects = MemberManager()
current_members = CurrentMemberManager()
active_members = ActiveMemberManager() active_members = ActiveMemberManager()
def __str__(self): def __str__(self):
......
...@@ -16,7 +16,7 @@ class MemberBirthdayTest(TestCase): ...@@ -16,7 +16,7 @@ class MemberBirthdayTest(TestCase):
def _get_members(self, start, end): def _get_members(self, start, end):
start_date = self._make_date(start) start_date = self._make_date(start)
end_date = self._make_date(end) end_date = self._make_date(end)
return Member.active_members.with_birthdays_in_range( return Member.current_members.with_birthdays_in_range(
start_date, end_date start_date, end_date
) )
......
...@@ -182,7 +182,7 @@ def iban_export(request): ...@@ -182,7 +182,7 @@ def iban_export(request):
header_fields = ['name', 'username', 'iban'] header_fields = ['name', 'username', 'iban']
rows = [] rows = []
members = models.Member.active_members.filter( members = models.Member.current_members.filter(
profile__direct_debit_authorized=True) profile__direct_debit_authorized=True)
for member in members: for member in members:
...@@ -210,7 +210,7 @@ def statistics(request): ...@@ -210,7 +210,7 @@ def statistics(request):
member_types = ("member", "supporter", "honorary") member_types = ("member", "supporter", "honorary")
# The numbers # The numbers
total = models.Member.active_members.count() total = models.Member.current_members.count()
context = { context = {
"total_members": total, "total_members": total,
......
...@@ -69,7 +69,7 @@ def admin_send(request, pk): ...@@ -69,7 +69,7 @@ def admin_send(request, pk):
translation.activate(language[0]) translation.activate(language[0])
recipients = [member.email for member in recipients = [member.email for member in
Member.active_members.all().filter( Member.current_members.all().filter(
profile__receive_newsletter=True, profile__receive_newsletter=True,
profile__language=language[0]) profile__language=language[0])
if member.email] if member.email]
......
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