Skip to content

Commit

Permalink
add a test_email option to send_welcome emails
Browse files Browse the repository at this point in the history
Lets you send out a test email so you can check it all looks ok
  • Loading branch information
struan committed Oct 2, 2024
1 parent 96f95eb commit e074608
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions crowdsourcer/management/commands/send_welcome_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"])

Expand Down

0 comments on commit e074608

Please sign in to comment.