def remove_notifications(email_notification_ids=None): """Remove sent emails. :param email_notification_ids: :return: """ for email_id in email_notification_ids: NotificationDigest.remove(Q('_id', 'eq', email_id))
def test_remove_sent_digest_notifications(self): d = factories.NotificationDigestFactory( user_id=factories.UserFactory()._id, timestamp=datetime.datetime.utcnow(), message='Hello', node_lineage=[factories.ProjectFactory()._id] ) digest_id = d._id remove_sent_digest_notifications(digest_notification_ids=[digest_id]) with assert_raises(NoResultsFound): NotificationDigest.find_one(Q('_id', 'eq', digest_id))
def test_send_email_digest_not_created_for_user_performed_actions(self): subscribed_users = [self.user] digest_count_before = NotificationDigest.find().count() emails.email_digest(subscribed_users, self.project._id, 'comments', nodeType='project', timestamp=datetime.datetime.utcnow().replace(tzinfo=pytz.utc), commenter=self.user, gravatar_url=self.user.gravatar_url, content='', parent_comment='', title=self.project.title, url=self.project.absolute_url ) digest_count = NotificationDigest.find().count() assert_equal(digest_count_before, digest_count)
def email_digest(recipient_ids, uid, event, user, node, timestamp, **context): """ Render the email message from context vars and store in the NotificationDigest objects created for each subscribed user. """ template = event + '.html.mako' context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for user_id in recipient_ids: recipient = website_models.User.load(user_id) context['localized_timestamp'] = localize_timestamp( timestamp, recipient) message = mails.render_message(template, **context) if user._id != recipient._id: digest = NotificationDigest(timestamp=timestamp, event=event, user_id=recipient._id, message=message, node_lineage=node_lineage_ids) digest.save()
def email_digest(recipient_ids, uid, event, user, node, timestamp, **context): """ Render the email message from context vars and store in the NotificationDigest objects created for each subscribed user. """ template = event + '.html.mako' context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for user_id in recipient_ids: recipient = website_models.User.load(user_id) context['localized_timestamp'] = localize_timestamp(timestamp, recipient) message = mails.render_message(template, **context) if user._id != recipient._id: digest = NotificationDigest( timestamp=timestamp, event=event, user_id=recipient._id, message=message, node_lineage=node_lineage_ids ) digest.save()
def email_digest(subscribed_user_ids, uid, event, **context): """ Render the email message from context vars and store in the NotificationDigest objects created for each subscribed user. """ template = event + '.html.mako' node = website_models.Node.load(uid) node_lineage_ids = get_node_lineage(node) if node else [] for user_id in subscribed_user_ids: user = website_models.User.load(user_id) context['localized_timestamp'] = localize_timestamp( context.get('timestamp'), user) message = mails.render_message(template, **context) if context.get('commenter')._id != user._id: digest = NotificationDigest(timestamp=context.get('timestamp'), event=event, user_id=user._id, message=message, node_lineage=node_lineage_ids) digest.save()
def email_digest(subscribed_user_ids, uid, event, **context): """ Render the email message from context vars and store in the NotificationDigest objects created for each subscribed user. """ template = event + '.html.mako' node = website_models.Node.load(uid) node_lineage_ids = get_node_lineage(node) if node else [] for user_id in subscribed_user_ids: user = website_models.User.load(user_id) context['localized_timestamp'] = localize_timestamp(context.get('timestamp'), user) message = mails.render_message(template, **context) if context.get('commenter')._id != user._id: digest = NotificationDigest( timestamp=context.get('timestamp'), event=event, user_id=user._id, message=message, node_lineage=node_lineage_ids ) digest.save()
def store_emails(recipient_ids, notification_type, event, user, node, timestamp, **context): """Store notification emails Emails are sent via celery beat as digests :param recipient_ids: List of user ids to send mail to. :param notification_type: from constants.Notification_types :param event: event that triggered notification :param user: user who triggered the notification :param node: instance of Node :param timestamp: time event happened :param context: :return: -- """ if notification_type == 'none': return template = event + '.html.mako' context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for user_id in recipient_ids: if user_id == user._id: continue recipient = website_models.User.load(user_id) context['localized_timestamp'] = localize_timestamp( timestamp, recipient) message = mails.render_message(template, **context) digest = NotificationDigest(timestamp=timestamp, send_type=notification_type, event=event, user_id=user_id, message=message, node_lineage=node_lineage_ids) digest.save()
def store_emails(recipient_ids, notification_type, event, user, node, timestamp, **context): """Store notification emails Emails are sent via celery beat as digests :param recipient_ids: List of user ids to send mail to. :param notification_type: from constants.Notification_types :param event: event that triggered notification :param user: user who triggered the notification :param node: instance of Node :param timestamp: time event happened :param context: :return: -- """ if notification_type == 'none': return template = event + '.html.mako' context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for user_id in recipient_ids: if user_id == user._id: continue recipient = website_models.User.load(user_id) context['localized_timestamp'] = localize_timestamp(timestamp, recipient) message = mails.render_message(template, **context) digest = NotificationDigest( timestamp=timestamp, send_type=notification_type, event=event, user_id=user_id, message=message, node_lineage=node_lineage_ids ) digest.save()
def remove_sent_digest_notifications(digest_notification_ids=None): for digest_id in digest_notification_ids: NotificationDigest.remove(Q('_id', 'eq', digest_id))