def send_abstract_notifications(abstract): """Send abstract notification e-mails. :param abstract: the abstract that is going to be checked against the event's notification rules :return: whether an email has been sent """ sent = False for email_tpl in abstract.event.abstract_email_templates: matched = False for rule in email_tpl.rules: if check_rule('abstract-notifications', rule, abstract=abstract, event=abstract.event): matched = True to_recipients = [] if email_tpl.include_submitter: to_recipients.append(abstract.submitter.email) if email_tpl.include_authors: to_recipients += [author.email for author in abstract.primary_authors] cc_recipients = list(email_tpl.extra_cc_emails) if email_tpl.include_coauthors: cc_recipients += [author.email for author in abstract.secondary_authors] tpl = get_abstract_notification_tpl_module(email_tpl, abstract) email = make_email(to_list=to_recipients, cc_list=cc_recipients, reply_address=email_tpl.reply_to_address, template=tpl) send_email(email, abstract.event, 'Abstracts', session.user) abstract.email_logs.append(AbstractEmailLogEntry.create_from_email(email, email_tpl=email_tpl, user=session.user)) sent = True if email_tpl.stop_on_match and matched: break return sent
def send_abstract_notifications(abstract): """Send abstract notification e-mails. :param abstract: the abstract that is going to be checked against the event's notification rules """ for email_tpl in abstract.event_new.abstract_email_templates: matched = False for rule in email_tpl.rules: if check_rule('abstract-notifications', rule, abstract=abstract, event=abstract.event_new): matched = True to_recipients = [] if email_tpl.include_submitter: to_recipients.append(abstract.submitter.email) if email_tpl.include_authors: to_recipients += [author.email for author in abstract.primary_authors] cc_recipients = list(email_tpl.extra_cc_emails) if email_tpl.include_coauthors: cc_recipients += [author.email for author in abstract.secondary_authors] tpl = get_abstract_notification_tpl_module(email_tpl, abstract) email = make_email(to_list=to_recipients, cc_list=cc_recipients, reply_address=email_tpl.reply_to_address, template=tpl) send_email(email, event=abstract.event_new, user=session.user) abstract.email_logs.append(AbstractEmailLogEntry.create_from_email(email, email_tpl=email_tpl, user=session.user)) if email_tpl.stop_on_match and matched: break
def test_check_rules(rule, kwargs, expected): assert check_rule('test', rule, **kwargs) == expected