def handle_noargs(self, **options): """The function running the command.""" translation.activate(django_settings.LANGUAGE_CODE) if askbot_settings.ENABLE_EMAIL_ALERTS is False: return if askbot_settings.ENABLE_UNANSWERED_REMINDERS is False: return #select questions within the range of the reminder schedule schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER, askbot_settings.UNANSWERED_REMINDER_FREQUENCY, max_reminders=askbot_settings.MAX_UNANSWERED_REMINDERS) if schedule.start_cutoff_date == schedule.end_cutoff_date: return questions = self.get_questions(schedule) if questions.count() == 0: return # for each eligible user send a somewhat personalized email if # they agreed to receiving those emails for user in self.get_users(): user.add_missing_askbot_subscriptions() email_setting = user.notification_subscriptions.filter( feed_type='q_noans')[0] if not email_setting.should_send_now(): continue filtered_questions = self.get_filtered_question_list( questions, user, schedule) if not filtered_questions: continue self.send_email(user, filtered_questions)
def handle_noargs(self, **options): if askbot_settings.ENABLE_EMAIL_ALERTS == False: return if askbot_settings.ENABLE_ACCEPT_ANSWER_REMINDERS == False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_ACCEPT_ANSWER_REMINDER, askbot_settings.ACCEPT_ANSWER_REMINDER_FREQUENCY, askbot_settings.MAX_ACCEPT_ANSWER_REMINDERS) questions = models.Post.objects.get_questions().exclude( deleted=True).added_between( start=schedule.start_cutoff_date, end=schedule.end_cutoff_date ).filter(thread__answer_count__gt=0).filter( thread__accepted_answer__isnull=True #answer_accepted = False ).order_by('-added_at') #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.filter(author=user) final_question_list = user_questions.get_questions_needing_reminder( activity_type=const.TYPE_ACTIVITY_ACCEPT_ANSWER_REMINDER_SENT, user=user, recurrence_delay=schedule.recurrence_delay) #todo: rewrite using query set filter #may be a lot more efficient question_count = len(final_question_list) if question_count == 0: continue reminder_phrase = _('Please select the best responses to:') data = { 'site_url': site_url(''), #here we need only the domain name 'questions': final_question_list, 'reminder_phrase': reminder_phrase, 'recipient_user': user } template = get_template('email/accept_answer_reminder.html') body_text = template.render(Context(data)) #todo: set lang subject_line = askbot_settings.WORDS_ACCEPT_BEST_ANSWERS_FOR_YOUR_QUESTIONS if DEBUG_THIS_COMMAND: print "User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, subject_line, body_text) else: mail.send_mail(subject_line=subject_line, body_text=body_text, recipient_list=(user.email, ))
def handle(self, **options): translation.activate(django_settings.LANGUAGE_CODE) if askbot_settings.ENABLE_EMAIL_ALERTS == False: return if askbot_settings.ENABLE_ACCEPT_ANSWER_REMINDERS == False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_ACCEPT_ANSWER_REMINDER, askbot_settings.ACCEPT_ANSWER_REMINDER_FREQUENCY, askbot_settings.MAX_ACCEPT_ANSWER_REMINDERS ) questions = models.Post.objects.get_questions().exclude( deleted = True ).added_between( start = schedule.start_cutoff_date, end = schedule.end_cutoff_date ).filter( thread__answer_count__gt = 0 ).filter( thread__accepted_answer__isnull=True #answer_accepted = False ).order_by('-added_at') #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(askbot_profile__status = 'b'): user_questions = questions.filter(author=user) final_question_list = user_questions.get_questions_needing_reminder( activity_type=const.TYPE_ACTIVITY_ACCEPT_ANSWER_REMINDER_SENT, user=user, recurrence_delay=schedule.recurrence_delay ) #todo: rewrite using query set filter #may be a lot more efficient question_count = len(final_question_list) if question_count == 0: continue email = AcceptAnswersReminder({ 'questions': final_question_list, 'recipient_user': user }) if DEBUG_THIS_COMMAND: print("User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, email.render_subject(), email.render_body())) else: email.send([user.email],)
def handle_noargs(self, **options): """The function running the command.""" translation.activate(django_settings.LANGUAGE_CODE) if askbot_settings.ENABLE_EMAIL_ALERTS is False: return if askbot_settings.ENABLE_UNANSWERED_REMINDERS is False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER, askbot_settings.UNANSWERED_REMINDER_FREQUENCY, max_reminders=askbot_settings.MAX_UNANSWERED_REMINDERS) 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.filter( askbot_profile__status__in=recipient_statuses): user.add_missing_askbot_subscriptions() email_setting = user.notification_subscriptions.filter( feed_type='q_noans')[0] if not email_setting.should_send_now(): continue user_questions = questions.exclude(author=user) user_questions = user.get_tag_filtered_questions(user_questions) if askbot_settings.GROUPS_ENABLED: user_groups = user.get_groups() user_questions = user_questions.filter(groups__in=user_groups) final_question_list = user_questions.get_questions_needing_reminder( user=user, activity_type=const.TYPE_ACTIVITY_UNANSWERED_REMINDER_SENT, recurrence_delay=schedule.recurrence_delay) question_count = len(final_question_list) if question_count == 0: continue email = UnansweredQuestionsReminder({ 'recipient_user': user, 'questions': final_question_list }) if DEBUG_THIS_COMMAND: print("User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, email.render_subject(), email.render_body())) else: email.send([ user.email, ])
def handle_noargs(self, **options): if askbot_settings.ENABLE_EMAIL_ALERTS == False: return if askbot_settings.ENABLE_UNANSWERED_REMINDERS == False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER, askbot_settings.UNANSWERED_REMINDER_FREQUENCY, 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') #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) user_questions = user.get_tag_filtered_questions(user_questions) final_question_list = user_questions.get_questions_needing_reminder( user = user, activity_type = const.TYPE_ACTIVITY_UNANSWERED_REMINDER_SENT, recurrence_delay = schedule.recurrence_delay ) question_count = len(final_question_list) if question_count == 0: continue threads = Thread.objects.filter(id__in=[qq.thread_id for qq in final_question_list]) tag_summary = Thread.objects.get_tag_summary_from_threads(threads) subject_line = ungettext( '%(question_count)d unanswered question about %(topics)s', '%(question_count)d unanswered questions about %(topics)s', question_count ) % { 'question_count': question_count, 'topics': tag_summary } body_text = '<ul>' for question in final_question_list: body_text += '<li><a href="%s%s?sort=latest">%s</a></li>' \ % ( askbot_settings.APP_URL, question.get_absolute_url(), question.thread.title ) body_text += '</ul>' if DEBUG_THIS_COMMAND: print "User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, subject_line, body_text) else: mail.send_mail( subject_line = subject_line, body_text = body_text, recipient_list = (user.email,) )
def handle_noargs(self, **options): if askbot_settings.ENABLE_ACCEPT_ANSWER_REMINDERS == False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_ACCEPT_ANSWER_REMINDER, askbot_settings.ACCEPT_ANSWER_REMINDER_FREQUENCY, askbot_settings.MAX_ACCEPT_ANSWER_REMINDERS ) questions = models.Question.objects.exclude( deleted = True ).added_between( start = schedule.start_cutoff_date, end = schedule.end_cutoff_date ).filter( answer_count__gt = 0 ).filter( answer_accepted = False ).order_by('-added_at') #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.filter(author = user) final_question_list = user_questions.get_questions_needing_reminder( activity_type = const.TYPE_ACTIVITY_ACCEPT_ANSWER_REMINDER_SENT, user = user, recurrence_delay = schedule.recurrence_delay ) #todo: rewrite using query set filter #may be a lot more efficient question_count = len(final_question_list) if question_count == 0: continue #tag_summary = get_tag_summary_from_questions(final_question_list) subject_line = _( 'Accept the best answer for %(question_count)d of your questions' ) % {'question_count': question_count} #todo - make a template for these if question_count == 1: reminder_phrase = _('Please accept the best answer for this question:') else: reminder_phrase = _('Please accept the best answer for these questions:') body_text = '<p>' + reminder_phrase + '</p>' body_text += '<ul>' for question in final_question_list: body_text += '<li><a href="%s%s?sort=latest">%s</a></li>' \ % ( askbot_settings.APP_URL, question.get_absolute_url(), question.title ) body_text += '</ul>' if DEBUG_THIS_COMMAND: print "User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, subject_line, body_text) else: mail.send_mail( subject_line = subject_line, body_text = body_text, recipient_list = (user.email,) )
def handle_noargs(self, **options): if askbot_settings.ENABLE_EMAIL_ALERTS == False: return if askbot_settings.ENABLE_UNANSWERED_REMINDERS == False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER, askbot_settings.UNANSWERED_REMINDER_FREQUENCY, 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') #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) user_questions = user.get_tag_filtered_questions(user_questions) if askbot_settings.GROUPS_ENABLED: user_groups = user.get_groups() user_questions = user_questions.filter(groups__in=user_groups) final_question_list = user_questions.get_questions_needing_reminder( user=user, activity_type=const.TYPE_ACTIVITY_UNANSWERED_REMINDER_SENT, recurrence_delay=schedule.recurrence_delay) question_count = len(final_question_list) if question_count == 0: continue threads = Thread.objects.filter( id__in=[qq.thread_id for qq in final_question_list]) tag_summary = Thread.objects.get_tag_summary_from_threads(threads) subject_line = ungettext( '%(question_count)d unanswered question about %(topics)s', '%(question_count)d unanswered questions about %(topics)s', question_count) % { 'question_count': question_count, 'topics': tag_summary } data = { 'site_url': site_url(''), 'questions': final_question_list, 'subject_line': subject_line } template = get_template('email/unanswered_question_reminder.html') body_text = template.render(Context(data)) #todo: set lang if TRACK_USER_EMAIL: print "%s:%s" % (user.email, subject_line) if DEBUG_THIS_COMMAND: print "User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, subject_line, body_text) else: mail.send_mail(subject_line=subject_line, body_text=body_text, recipient_list=(user.email, ))
def handle_noargs(self, **options): if askbot_settings.ENABLE_EMAIL_ALERTS == False: return if askbot_settings.ENABLE_UNANSWERED_REMINDERS == False: return #get questions without answers, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER, askbot_settings.UNANSWERED_REMINDER_FREQUENCY, max_reminders=askbot_settings.MAX_UNANSWERED_REMINDERS) 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.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: user_groups = user.get_groups() user_questions = user_questions.filter(groups__in=user_groups) final_question_list = user_questions.get_questions_needing_reminder( user=user, activity_type=const.TYPE_ACTIVITY_UNANSWERED_REMINDER_SENT, recurrence_delay=schedule.recurrence_delay) question_count = len(final_question_list) if question_count == 0: continue threads = Thread.objects.filter( id__in=[qq.thread_id for qq in final_question_list]) tag_summary = Thread.objects.get_tag_summary_from_threads(threads) if question_count == 1: unanswered_questions_phrase = askbot_settings.WORDS_UNANSWERED_QUESTION_SINGULAR else: unanswered_questions_phrase = askbot_settings.WORDS_UNANSWERED_QUESTION_PLURAL subject_line = ungettext( '%(question_count)d %(unanswered_questions)s about %(topics)s', '%(question_count)d %(unanswered_questions)s about %(topics)s', question_count) % { 'question_count': question_count, 'unanswered_questions': unanswered_questions_phrase, 'topics': tag_summary } data = { 'site_url': site_url(''), 'questions': final_question_list, 'subject_line': subject_line } template = get_template('email/unanswered_question_reminder.html') body_text = template.render(Context(data)) #todo: set lang if DEBUG_THIS_COMMAND: print "User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, subject_line, body_text) else: mail.send_mail(subject_line=subject_line, body_text=body_text, recipient_list=(user.email, ))
def handle_noargs(self, **options): if askbot_settings.ENABLE_EMAIL_ALERTS == False: return if askbot_settings.ENABLE_ACCEPT_PROBLEM_REMINDERS == False: return #get exercises without problems, excluding closed and deleted #order it by descending added_at date schedule = ReminderSchedule( askbot_settings.DAYS_BEFORE_SENDING_ACCEPT_PROBLEM_REMINDER, askbot_settings.ACCEPT_PROBLEM_REMINDER_FREQUENCY, askbot_settings.MAX_ACCEPT_PROBLEM_REMINDERS) exercises = models.Post.objects.get_exercises( ).exclude(deleted=True).added_between( start=schedule.start_cutoff_date, end=schedule.end_cutoff_date ).filter(thread__problem_count__gt=0).filter( thread__accepted_problem__isnull=True #problem_accepted = False ).order_by('-added_at') #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_exercises = exercises.filter(author=user) final_exercise_list = user_exercises.get_exercises_needing_reminder( activity_type=const.TYPE_ACTIVITY_ACCEPT_PROBLEM_REMINDER_SENT, user=user, recurrence_delay=schedule.recurrence_delay) #todo: rewrite using query set filter #may be a lot more efficient exercise_count = len(final_exercise_list) if exercise_count == 0: continue subject_line = _( 'Accept the best problem for %(exercise_count)d of your exercises' ) % { 'exercise_count': exercise_count } #todo - make a template for these if exercise_count == 1: reminder_phrase = _( 'Please accept the best problem for this exercise:') else: reminder_phrase = _( 'Please accept the best problem for these exercises:') data = { 'site_url': askbot_settings.APP_URL, 'exercises': final_exercise_list, 'reminder_phrase': reminder_phrase } template = get_template('email/accept_problem_reminder.html') body_text = template.render(Context(data)) if DEBUG_THIS_COMMAND: print "User: %s<br>\nSubject:%s<br>\nText: %s<br>\n" % \ (user.email, subject_line, body_text) else: mail.send_mail(subject_line=subject_line, body_text=body_text, recipient_list=(user.email, ))