enable --debug-email for start and runserver

closes #5702
This commit is contained in:
Finn Stutzenstein 2020-11-25 14:52:51 +01:00
parent 03cb8592fe
commit 667a841051
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
2 changed files with 28 additions and 5 deletions

View File

@ -215,10 +215,6 @@ def start(args):
# A manual given environment variable will be overwritten
setup_django_settings_module(settings_path, local_installation=local_installation)
django.setup()
from django.conf import settings
if args.debug_email:
settings.EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Migrate database
call_command("migrate")
@ -232,7 +228,7 @@ def start(args):
# Start the built-in webserver
#
# Use flag --noreload to tell Django not to reload the server.
# Therefor we have to set the keyword noreload to False because Django
# Therefore we have to set the keyword noreload to False because Django
# parses this directly to the use_reloader keyword.
#
# Use flag --insecure to serve static files even if DEBUG is False.
@ -241,6 +237,7 @@ def start(args):
f"{args.host}:{args.port}",
noreload=False, # Means True, see above.
insecure=True,
debug_email=args.debug_email,
)

View File

@ -0,0 +1,26 @@
from django.contrib.staticfiles.management.commands.runserver import (
Command as RunserverCommand,
)
class Command(RunserverCommand):
"""
Enables the --debug-email flag
"""
def add_arguments(self, parser):
super().add_arguments(parser)
parser.add_argument(
"--debug-email",
action="store_true",
help="Change the email backend to console output.",
)
def handle(self, *args, **options):
from django.conf import settings
if options["debug_email"]:
self.stdout.write("Enabled debug email")
settings.EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
return super().handle(*args, **options)