From 3cf1ba60b8826141392bb93bb5fdfd749cc2adb7 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 12 Oct 2014 15:49:53 -0300 Subject: allowed admins&mods or everyone receive unanswered question notifications --- askbot/conf/email.py | 15 ++++++++ .../commands/send_unanswered_question_reminders.py | 43 ++++++++++++++++------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/askbot/conf/email.py b/askbot/conf/email.py index cbdb2ba1..2cf5460e 100644 --- a/askbot/conf/email.py +++ b/askbot/conf/email.py @@ -159,6 +159,21 @@ settings.register( ) ) +UNANSWERED_REMINDER_RECIPIENTS_CHOICES = ( + ('everyone', _('everyone')), + ('admins', _('moderators & administrators')) +) + +settings.register( + livesettings.StringValue( + EMAIL, + 'UNANSWERED_REMINDER_RECIPIENTS', + default='everyone', + choices=UNANSWERED_REMINDER_RECIPIENTS_CHOICES, + description=_('Whom to remind about unanswered questions') + ) +) + settings.register( livesettings.IntegerValue( EMAIL, diff --git a/askbot/management/commands/send_unanswered_question_reminders.py b/askbot/management/commands/send_unanswered_question_reminders.py index 54d06996..70f830f1 100644 --- a/askbot/management/commands/send_unanswered_question_reminders.py +++ b/askbot/management/commands/send_unanswered_question_reminders.py @@ -1,4 +1,5 @@ from django.core.management.base import NoArgsCommand +from django.db.models import Q from django.template.loader import get_template from askbot import models from askbot import const @@ -29,21 +30,39 @@ class Command(NoArgsCommand): max_reminders = askbot_settings.MAX_UNANSWERED_REMINDERS ) - questions = models.Post.objects.get_questions().exclude( - thread__closed = True - ).exclude( - deleted = True - ).added_between( - start = schedule.start_cutoff_date, - end = schedule.end_cutoff_date - ).filter( - thread__answer_count = 0 - ).order_by('-added_at') + questions = models.Post.objects.get_questions() + + #we don't report closed, deleted or moderation queue questions + exclude_filter = Q(thread__closed=True) | Q(deleted=True) + if askbot_settings.CONTENT_MODERATION_MODE == 'premoderation': + exclude_filter |= Q(approved=False) + questions = questions.exclude(exclude_filter) + + #select questions within the range of the reminder schedule + questions = questions.added_between( + start=schedule.start_cutoff_date, + end=schedule.end_cutoff_date + ) + + #take only questions with zero answers + questions = questions.filter(thread__answer_count=0) + + if questions.count() == 0: + #nothing to do + return + + questions = questions.order_by('-added_at') + + if askbot_settings.UNANSWERED_REMINDER_RECIPIENTS == 'admins': + recipient_statuses = ('d', 'm') + else: + recipient_statuses = ('a', 'w', 'd', 'm') + #for all users, excluding blocked #for each user, select a tag filtered subset #format the email reminder and send it - for user in models.User.objects.exclude(status = 'b'): - user_questions = questions.exclude(author = user) + for user in models.User.objects.filter(status__in=recipient_statuses): + user_questions = questions.exclude(author=user) user_questions = user.get_tag_filtered_questions(user_questions) if askbot_settings.GROUPS_ENABLED: -- cgit v1.2.3-1-g7c22