def send_instant_notifications_about_activity_in_post(update_activity=None, post=None, recipients=None): # reload object from the database post = Post.objects.get(id=post.id) if post.is_approved() is False: return if recipients is None: return acceptable_types = const.RESPONSE_ACTIVITY_TYPES_FOR_INSTANT_NOTIFICATIONS if update_activity.activity_type not in acceptable_types: return # calculate some variables used in the loop below update_type_map = const.RESPONSE_ACTIVITY_TYPE_MAP_FOR_TEMPLATES update_type = update_type_map[update_activity.activity_type] origin_post = post.get_origin_post() headers = mail.thread_headers(post, origin_post, update_activity.activity_type) logger = logging.getLogger() if logger.getEffectiveLevel() <= logging.DEBUG: log_id = uuid.uuid1() message = "email-alert %s, logId=%s" % (post.get_absolute_url(), log_id) logger.debug(message) else: log_id = None for user in recipients: if user.is_blocked(): continue reply_address, alt_reply_address = get_reply_to_addresses(user, post) subject_line, body_text = format_instant_notification_email( to_user=user, from_user=update_activity.user, post=post, reply_address=reply_address, alt_reply_address=alt_reply_address, update_type=update_type, template=get_template("email/instant_notification.html"), ) headers["Reply-To"] = reply_address try: mail.send_mail( subject_line=subject_line, body_text=body_text, recipient_list=[user.email], related_object=origin_post, activity_type=const.TYPE_ACTIVITY_EMAIL_UPDATE_SENT, headers=headers, raise_on_failure=True, ) except askbot_exceptions.EmailNotSent, error: logger.debug("%s, error=%s, logId=%s" % (user.email, error, log_id)) else: logger.debug("success %s, logId=%s" % (user.email, log_id))
def send_instant_notifications_about_activity_in_post( activity_id=None, post_id=None, recipients=None, ): if recipients is None: return acceptable_types = const.RESPONSE_ACTIVITY_TYPES_FOR_INSTANT_NOTIFICATIONS try: update_activity = Activity.objects.filter( activity_type__in=acceptable_types).get(id=activity_id) except Activity.DoesNotExist: logger.error("Unable to fetch activity with id %s" % post_id) return try: post = Post.objects.get(id=post_id) except Post.DoesNotExist: logger.error("Unable to fetch post with id %s" % post_id) return if post.is_approved() is False: return #calculate some variables used in the loop below update_type_map = const.RESPONSE_ACTIVITY_TYPE_MAP_FOR_TEMPLATES update_type = update_type_map[update_activity.activity_type] origin_post = post.get_origin_post() headers = mail.thread_headers(post, origin_post, update_activity.activity_type) if logger.getEffectiveLevel() <= logging.DEBUG: log_id = uuid.uuid1() message = 'email-alert %s, logId=%s' % (post.get_absolute_url(), log_id) logger.debug(message) else: log_id = None for user in recipients: if user.is_blocked(): continue reply_address, alt_reply_address = get_reply_to_addresses(user, post) activate_language(post.language_code) subject_line, body_text = format_instant_notification_email( to_user=user, from_user=update_activity.user, post=post, reply_address=reply_address, alt_reply_address=alt_reply_address, update_type=update_type, template=get_template('email/instant_notification.html')) headers['Reply-To'] = reply_address try: mail.send_mail(subject_line=subject_line, body_text=body_text, recipient_list=[user.email], related_object=origin_post, activity_type=const.TYPE_ACTIVITY_EMAIL_UPDATE_SENT, headers=headers, raise_on_failure=True) except askbot_exceptions.EmailNotSent, error: logger.debug('%s, error=%s, logId=%s' % (user.email, error, log_id)) else: logger.debug('success %s, logId=%s' % (user.email, log_id))