From d08ce9161ea653d7c4b1b114fdaf28bc1d45daf9 Mon Sep 17 00:00:00 2001 From: jordan Date: Thu, 7 Jul 2011 01:07:57 +0000 Subject: [PATCH] OSQA-706, send daily digest only to users that are active and have validated their emails. Everything has been wrapped in settings and that allows to easily turn off this two options (they default to True) and avoid panic from admins that expect different behavior. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1108 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/management/commands/send_email_alerts.py | 12 +++++++++++- forum/settings/email.py | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py index 80159e7..06cad53 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -91,7 +91,17 @@ class Command(NoArgsCommand): EMAIL_DIGEST_FLAG.set_value(digest_control) - users = User.objects.filter(subscription_settings__enable_notifications=True, subscription_settings__send_digest=True) + users = User.objects.filter(subscription_settings__enable_notifications=True, + subscription_settings__send_digest=True) + + # Send digest only to active users + if settings.SEND_DIGEST_ONLY_TO_ACTIVE_USERS: + users = users.filter(is_active=True) + + # Send digest only to users with validated emails + if settings.SEND_DIGEST_ONLY_TO_VALIDATED_USERS: + users = users.filter(email_isvalid=True) + new_members = User.objects.filter(is_active=True, date_joined__gt=from_date).annotate(n_actions=models.Count('actions')).order_by('-n_actions') new_member_count = new_members.count() diff --git a/forum/settings/email.py b/forum/settings/email.py index e934d30..583ab0d 100644 --- a/forum/settings/email.py +++ b/forum/settings/email.py @@ -68,6 +68,14 @@ label = _("Email Link Style"), help_text = _("A valid css string to be used to style email links (the A tag)."), required=False)) +SEND_DIGEST_ONLY_TO_ACTIVE_USERS = Setting('SEND_DIGEST_ONLY_TO_ACTIVE_USERS', True, EMAIL_SET, dict( +label = _("Send digest only to active users"), +help_text = _("If checked the daily digest won't be sent to users that have been suspended."), +required=False)) +SEND_DIGEST_ONLY_TO_VALIDATED_USERS = Setting('SEND_DIGEST_ONLY_TO_VALIDATED_USERS', True, EMAIL_SET, dict( +label = _("Send digest only to validated users"), +help_text = _("If checked the daily digest won't be sent to users that haven't validated their emails."), +required=False)) EMAIL_DIGEST_FLAG = Setting('EMAIL_DIGEST_FLAG', None) -- 2.39.5