From e074608a4d55ddb30c6d54cfe82f68c58f463f96 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 2 Oct 2024 10:19:31 +0100 Subject: [PATCH] add a test_email option to send_welcome emails Lets you send out a test email so you can check it all looks ok --- .../commands/send_welcome_emails.py | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/crowdsourcer/management/commands/send_welcome_emails.py b/crowdsourcer/management/commands/send_welcome_emails.py index e10c1c9..961046d 100644 --- a/crowdsourcer/management/commands/send_welcome_emails.py +++ b/crowdsourcer/management/commands/send_welcome_emails.py @@ -32,6 +32,10 @@ def add_arguments(self, parser): help="Use this session config and only send emails to people in this session", ) + parser.add_argument( + "--test_email", action="store", help="send a test email to this address" + ) + def get_config(self, session): if settings.WELCOME_EMAIL.get(session): return settings.WELCOME_EMAIL[session] @@ -44,25 +48,34 @@ def handle(self, *args, **kwargs): f"{YELLOW}Not sending emails. Call with --send_emails to send{NOBOLD}" ) - users = Marker.objects.filter(send_welcome_email=True).select_related("user") - - if kwargs["stage"]: - try: - rt = ResponseType.objects.get(type=kwargs["stage"]) - users = users.filter(response_type=rt) - except ResponseType.NotFoundException: - self.stderr.write(f"{YELLOW}No such stage: {kwargs['stage']}{NOBOLD}") - return + if kwargs["test_email"]: + users = Marker.objects.filter( + user__email=kwargs["test_email"] + ).select_related("user") + else: + users = Marker.objects.filter(send_welcome_email=True).select_related( + "user" + ) - if kwargs["session"]: - try: - session = MarkingSession.objects.get(label=kwargs["session"]) - users = users.filter(marking_session=session) - except ResponseType.NotFoundException: - self.stderr.write( - f"{YELLOW}No such session: {kwargs['session']}{NOBOLD}" - ) - return + if kwargs["stage"]: + try: + rt = ResponseType.objects.get(type=kwargs["stage"]) + users = users.filter(response_type=rt) + except ResponseType.NotFoundException: + self.stderr.write( + f"{YELLOW}No such stage: {kwargs['stage']}{NOBOLD}" + ) + return + + if kwargs["session"]: + try: + session = MarkingSession.objects.get(label=kwargs["session"]) + users = users.filter(marking_session=session) + except ResponseType.NotFoundException: + self.stderr.write( + f"{YELLOW}No such session: {kwargs['session']}{NOBOLD}" + ) + return config = self.get_config(kwargs["session"])