X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/3d835e01926aeec21f78df2012567cdd2f2f7f07..6f16f6850fbdd4acb2a4f985b3a9dab0a3129e49:/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 1dd55ab..85b83fa 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -1,9 +1,10 @@ import datetime from forum.models import * +from forum import settings from django.db import models from forum.utils.mail import send_template_email from django.core.management.base import NoArgsCommand -from forum.settings.email import EMAIL_DIGEST_CONTROL +from forum.settings.email import EMAIL_DIGEST_FLAG from django.utils import translation import logging @@ -79,18 +80,18 @@ class Command(NoArgsCommand): except: logging.error("Unable to set the locale in the send emails cron job") - digest_control = EMAIL_DIGEST_CONTROL.value + digest_control = EMAIL_DIGEST_FLAG.value if digest_control is None: - digest_control = KeyValue(key='DIGEST_CONTROL', value={ + digest_control = { 'LAST_DAILY': datetime.datetime.now() - datetime.timedelta(days=1), 'LAST_WEEKLY': datetime.datetime.now() - datetime.timedelta(days=1), - }) + } - from_date = digest_control.value['LAST_DAILY'] - digest_control.value['LAST_DAILY'] = datetime.datetime.now() + from_date = digest_control['LAST_DAILY'] + digest_control['LAST_DAILY'] = datetime.datetime.now() - EMAIL_DIGEST_CONTROL.set_value(digest_control) + EMAIL_DIGEST_FLAG.set_value(digest_control) users = User.objects.filter(subscription_settings__enable_notifications=True, subscription_settings__send_digest=True) new_members = User.objects.filter(is_active=True, date_joined__gt=from_date).annotate(n_actions=models.Count('actions')).order_by('-n_actions') @@ -105,6 +106,9 @@ class Command(NoArgsCommand): digest = DigestQuestionsIndex(from_date) + if (not new_member_count) and (not digest.count): + return + send_template_email(users, "notifications/digest.html", locals())