X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/15f6ccf06354856b10422407037320b4e064d727..63ad88e2826d82b4ea7ff380784d471fa4884e3d:/forum/management/commands/send_email_alerts.py diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py index 02e2df0..06cad53 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -12,8 +12,6 @@ SHOW_N_MORE_ACTIVE_NEW_MEMBERS = 5 SUB_QUESTION_LIST_LENGTH = 5 TRY_N_USER_TAGS = 5 - - class DigestQuestionsIndex(object): def __init__(self, from_date): self.from_date = from_date @@ -93,13 +91,23 @@ 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() # The number of the flagged content for the day - flagged_count = Flag.objects.all().count() + flagged_count = Flag.objects.filter(flagged_at__gt=datetime.datetime.today()-datetime.timedelta(days=1)).count() if new_member_count >= SHOW_N_MORE_ACTIVE_NEW_MEMBERS: new_members = new_members[:SHOW_N_MORE_ACTIVE_NEW_MEMBERS]