Files
zulip/zerver/management/commands/turn_off_digests.py
Tim Abbott 8e7ce7cc79 python: Sort migrations/management command imports with isort.
This is a preparatory commit for using isort for sorting all of our
imports, merging changes to files where we can easily review the
changes as something we're happy with.

These are also files with relatively little active development, which
means we don't expect much merge conflict risk from these changes.
2020-01-14 13:07:47 -08:00

31 lines
1.3 KiB
Python

from django.core.management.base import CommandParser
from zerver.lib.actions import do_change_notification_settings
from zerver.lib.management import ZulipBaseCommand
class Command(ZulipBaseCommand):
help = """Turn off digests for a subdomain/string_id or specified set of email addresses."""
def add_arguments(self, parser: CommandParser) -> None:
self.add_realm_args(parser)
self.add_user_list_args(parser,
help='Turn off digests for this comma-separated '
'list of email addresses.',
all_users_help="Turn off digests for everyone in realm.")
def handle(self, **options: str) -> None:
realm = self.get_realm(options)
user_profiles = self.get_users(options, realm)
print("Turned off digest emails for:")
for user_profile in user_profiles:
already_disabled_prefix = ""
if user_profile.enable_digest_emails:
do_change_notification_settings(user_profile, 'enable_digest_emails', False)
else:
already_disabled_prefix = "(already off) "
print("%s%s <%s>" % (already_disabled_prefix, user_profile.full_name,
user_profile.delivery_email))