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

Rename ActiveMemberManager to CurrentMemberManager

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