diff --git a/server/openslides/__main__.py b/server/openslides/__main__.py index ccee63dd8..fb445b8b2 100644 --- a/server/openslides/__main__.py +++ b/server/openslides/__main__.py @@ -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, ) diff --git a/server/openslides/core/management/commands/runserver.py b/server/openslides/core/management/commands/runserver.py new file mode 100644 index 000000000..2cadcf4da --- /dev/null +++ b/server/openslides/core/management/commands/runserver.py @@ -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)