def email_transactional(recipient_ids, uid, event, user, node, timestamp, **context): """ :param recipient_ids: mod-odm User object ids :param uid: id of the event owner (Node or User) :param event: name of notification event (e.g. 'comments') :param context: context variables for email template See notify for specifics :return: """ template = event + '.html.mako' context['title'] = node.title context['user'] = user subject = Template(EMAIL_SUBJECT_MAP[event]).render(**context) for user_id in recipient_ids: recipient = website_models.User.load(user_id) email = recipient.username context['localized_timestamp'] = localize_timestamp(timestamp, recipient) message = mails.render_message(template, **context) if user._id != recipient._id: mails.send_mail( to_addr=email, mail=mails.TRANSACTIONAL, mimetype='html', name=recipient.fullname, node_id=node._id, node_title=node.title, subject=subject, message=message, url=get_settings_url(uid, recipient) )
def email_transactional(subscribed_user_ids, uid, event, **context): """ :param subscribed_user_ids: mod-odm User object ids :param uid: id of the event owner (Node or User) :param event: name of notification event (e.g. 'comments') :param context: context variables for email template :return: """ template = event + '.html.mako' subject = Template(EMAIL_SUBJECT_MAP[event]).render(**context) for user_id in subscribed_user_ids: user = website_models.User.load(user_id) email = user.username context['localized_timestamp'] = localize_timestamp( context.get('timestamp'), user) message = mails.render_message(template, **context) if context.get('commenter')._id != user._id: mails.send_mail(to_addr=email, mail=mails.TRANSACTIONAL, mimetype='html', name=user.fullname, node_id=context.get('node_id'), node_title=context.get('title'), subject=subject, message=message, url=get_settings_url(uid, user))
def email_transactional(subscribed_user_ids, uid, event, **context): """ :param subscribed_user_ids: mod-odm User object ids :param uid: id of the event owner (Node or User) :param event: name of notification event (e.g. 'comments') :param context: context variables for email template :return: """ template = event + '.html.mako' subject = Template(EMAIL_SUBJECT_MAP[event]).render(**context) for user_id in subscribed_user_ids: user = website_models.User.load(user_id) email = user.username context['localized_timestamp'] = localize_timestamp(context.get('timestamp'), user) message = mails.render_message(template, **context) if context.get('commenter')._id != user._id: mails.send_mail( to_addr=email, mail=mails.TRANSACTIONAL, mimetype='html', name=user.fullname, node_id=context.get('node_id'), node_title=context.get('title'), subject=subject, message=message, url=get_settings_url(uid, user) )
def email_transactional(recipient_ids, uid, event, user, node, timestamp, **context): """ :param recipient_ids: mod-odm User object ids :param uid: id of the event owner (Node or User) :param event: name of notification event (e.g. 'comments') :param context: context variables for email template See notify for specifics :return: """ template = event + '.html.mako' context['title'] = node.title context['user'] = user subject = Template(EMAIL_SUBJECT_MAP[event]).render(**context) for user_id in recipient_ids: recipient = website_models.User.load(user_id) email = recipient.username context['localized_timestamp'] = localize_timestamp( timestamp, recipient) message = mails.render_message(template, **context) if user._id != recipient._id: mails.send_mail(to_addr=email, mail=mails.TRANSACTIONAL, mimetype='html', name=recipient.fullname, node_id=node._id, node_title=node.title, subject=subject, message=message, url=get_settings_url(uid, recipient))
def test_send_email_transactional(self, send_mail): # assert that send_mail is called with the correct person & args subscribed_users = [self.user._id] timestamp = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) emails.email_transactional( subscribed_users, self.project._id, 'comments', nodeType='project', timestamp=timestamp, commenter=self.project.creator, gravatar_url=self.user.gravatar_url, content='', parent_comment='', title=self.project.title, node_id=self.project._id, url=self.project.absolute_url ) subject = Template(emails.EMAIL_SUBJECT_MAP['comments']).render( nodeType='project', timestamp=timestamp, commenter=self.project.creator, gravatar_url=self.user.gravatar_url, content='', parent_comment='', title=self.project.title, url=self.project.absolute_url) message = mails.render_message( 'comments.html.mako', nodeType='project', timestamp=timestamp, commenter=self.project.creator, gravatar_url=self.user.gravatar_url, content='', parent_comment='', title=self.project.title, url=self.project.absolute_url, localized_timestamp=emails.localize_timestamp(timestamp, self.user)) assert_true(send_mail.called) send_mail.assert_called_with( to_addr=self.user.username, mail=mails.TRANSACTIONAL, mimetype='html', name=self.user.fullname, node_title=self.project.title, node_id=self.project._id, subject=subject, message=message, url=self.project.absolute_url + 'settings/' )
def store_emails(recipient_ids, notification_type, event, user, node, timestamp, abstract_provider=None, template=None, **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 # If `template` is not specified, default to using a template with name `event` template = '{template}.html.mako'.format(template=template or event) # user whose action triggered email sending context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for recipient_id in recipient_ids: if recipient_id == user._id: continue recipient = OSFUser.load(recipient_id) if recipient.is_disabled: continue context['localized_timestamp'] = localize_timestamp( timestamp, recipient) context['recipient'] = recipient message = mails.render_message(template, **context) digest = NotificationDigest(timestamp=timestamp, send_type=notification_type, event=event, user=recipient, message=message, node_lineage=node_lineage_ids, provider=abstract_provider) digest.save()
def store_emails(recipient_ids, notification_type, event, user, node, timestamp, abstract_provider=None, template=None, **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 # If `template` is not specified, default to using a template with name `event` template = '{template}.html.mako'.format(template=template or event) # user whose action triggered email sending context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for recipient_id in recipient_ids: if recipient_id == user._id: continue recipient = OSFUser.load(recipient_id) if recipient.is_disabled: continue context['localized_timestamp'] = localize_timestamp(timestamp, recipient) context['recipient'] = recipient message = mails.render_message(template, **context) digest = NotificationDigest( timestamp=timestamp, send_type=notification_type, event=event, user=recipient, message=message, node_lineage=node_lineage_ids, provider=abstract_provider ) 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(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 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' # user whose action triggered email sending context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for recipient_id in recipient_ids: if recipient_id == user._id: continue recipient = OSFUser.load(recipient_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=recipient, 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' # user whose action triggered email sending context['user'] = user node_lineage_ids = get_node_lineage(node) if node else [] for recipient_id in recipient_ids: if recipient_id == user._id: continue recipient = OSFUser.load(recipient_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=recipient, 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()