From f85d45a781eef0ab6d7362dad45da94be4bbf8df Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Wed, 15 Jan 2014 10:08:39 -0500 Subject: [PATCH] Add a management command to bulk turn off digests. (imported from commit 0ffb565ecc9be219807ae9a45abb7b0e3e940204) --- .../management/commands/turn_off_digests.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 zerver/management/commands/turn_off_digests.py diff --git a/zerver/management/commands/turn_off_digests.py b/zerver/management/commands/turn_off_digests.py new file mode 100644 index 0000000000..6837f976f7 --- /dev/null +++ b/zerver/management/commands/turn_off_digests.py @@ -0,0 +1,46 @@ +from __future__ import absolute_import + +from optparse import make_option + +from django.core.management.base import BaseCommand + +from zerver.lib.actions import do_change_enable_digest_emails +from zerver.models import Realm, UserProfile, get_user_profile_by_email + +class Command(BaseCommand): + help = """Turn off digests for a domain or specified set of email addresses.""" + + option_list = BaseCommand.option_list + ( + make_option('-d', '--domain', + dest='domain', + type='str', + help='Turn off digests for all users in this domain.'), + make_option('-u', '--users', + dest='users', + type='str', + help='Turn off digests for this comma-separated list of email addresses.'), + ) + + def handle(self, **options): + if options["domain"] is None and options["users"] is None: + self.print_help("python manage.py", "turn_off_digests") + exit(1) + + if options["domain"]: + realm = Realm.objects.get(domain=options["domain"]) + user_profiles = UserProfile.objects.filter(realm=realm) + else: + emails = set([email.strip() for email in options["users"].split(",")]) + user_profiles = [] + for email in emails: + user_profiles.append(get_user_profile_by_email(email)) + + print "Turned off digest emails for:" + for user_profile in user_profiles: + already_disabled_prefix = "" + if user_profile.enable_digest_emails: + do_change_enable_digest_emails(user_profile, False) + else: + already_disabled_prefix = "(already off) " + print "%s%s <%s>" % (already_disabled_prefix, user_profile.full_name, + user_profile.email)