Skip to content

Commit 20117b6

Browse files
committed
Add management command send_individual_member_account_invite_mails
1 parent f1a4781 commit 20117b6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from django.core.management.base import BaseCommand
2+
from django.db import transaction
3+
4+
from ...models import IndividualMember, IndividualMemberAccountInviteSendMailStatus
5+
6+
7+
class Command(BaseCommand):
8+
def add_arguments(self, parser):
9+
parser.add_argument(
10+
"--include-former-members",
11+
action="store_true",
12+
help="Include former members to the queryset.",
13+
)
14+
15+
parser.add_argument(
16+
"--no-logging",
17+
action="store_true",
18+
help="Disable writing results to stdout/stderr.",
19+
)
20+
21+
def handle(self, *args, **options):
22+
queryset = IndividualMember.objects.filter(
23+
user_id__isnull=True,
24+
account_invite_mail_sent_at__isnull=True,
25+
)
26+
if not options["include_former_members"]:
27+
queryset = queryset.filter(member_until__isnull=True)
28+
with transaction.atomic():
29+
results = IndividualMember.send_account_invite_mails(queryset)
30+
if not options["no_logging"]:
31+
self.write_account_invite_send_mail_results(results)
32+
33+
def write_account_invite_send_mail_results(self, results):
34+
for (
35+
status_enum_member,
36+
status_enum_value,
37+
) in IndividualMemberAccountInviteSendMailStatus.__members__.items():
38+
count = results.get(status_enum_value, 0)
39+
writer = self.stdout
40+
if (
41+
status_enum_value == IndividualMemberAccountInviteSendMailStatus.FAILED
42+
and count > 0
43+
):
44+
writer = self.stderr
45+
writer.write(f"{status_enum_member}: {count}")

0 commit comments

Comments
 (0)