def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = self.get_recipients(job) if not recipients: return event = try_create(Event, where={ 'type': EventType.email, 'item_id': job.build_id, 'data': { 'recipients': recipients, } }) if not event: # We've already sent out notifications for this build return context = self.get_context(job, parent) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup(toronado.from_string( render_template('listeners/mail/notification.html', **context) )) mail.send(msg)
def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = self.get_recipients(job) if not recipients: return event = try_create(Event, where={ 'type': EventType.email, 'item_id': job.build_id, 'data': { 'recipients': recipients, } }) if not event: # We've already sent out notifications for this build return context = self.get_context(job, parent) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup( toronado.from_string( render_template('listeners/mail/notification.html', **context))) mail.send(msg)
def human_html(htm, parent=None, class_='email-quote'): htm = re.sub(r'(<br[ ]?[/]?>\s*)$', '', htm).strip() if htm and parent: htm = hide_quote(htm, parent, class_) if htm: htm = toronado.from_string(htm).decode() return htm
def get_msg(self, builds): # type: (List[Build]) -> Message context = build_context_lib.get_collection_context( builds) # type: CollectionContext if context.result == Result.passed: return None max_shown = current_app.config.get('MAX_SHOWN_ITEMS_PER_BUILD_MAIL', 3) context_dict = context._asdict() context_dict.update({ 'MAX_SHOWN_ITEMS_PER_BUILD': max_shown, 'showing_failing_tests_count': sum([ min(b['failing_tests_count'], max_shown) for b in context.builds ]) }) recipients = self.get_collection_recipients(context) msg = Message(context.title, recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context_dict) msg.html = Markup( toronado.from_string( render_template('listeners/mail/notification.html', **context_dict))) return msg
def get(self, path=''): projects = Project.query.all() report = BuildReport(projects) context = report.generate(days=int(request.args.get('days', 7))) html_content = Markup(toronado.from_string( render_template('email/build_report.html', **context) )) return render_template('debug/email.html', html_content=html_content)
def get_msg(self, context): recipients = self.get_collection_recipients(context) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup(toronado.from_string( render_template('listeners/mail/notification.html', **context) )) return msg
def render_email_body(template_name, context=None): """Generate text and HTML for an email body using the named email template, with substitutions provided by `context`. """ context = {} if context is None else context html = render_to_string("email/" + template_name + ".djhtml", context) try: text = render_to_string("email/" + template_name + ".djtxt", context) except TemplateDoesNotExist: text = strip_tags(html) html = toronado.from_string(html) return (html, text)
def render_email_body(template_name, context=None): """Generate text and HTML for an email body using the named email template, with substitutions provided by `context`. """ context = {} if context is None else context html = render_to_string(f"email/{template_name}.djhtml", context) try: text = render_to_string(f"email/{template_name}.djtxt", context) except TemplateDoesNotExist: text = strip_tags(html) html = toronado.from_string(html).decode("utf-8") return (html, text)
def get(self, job_id): job = Job.query.get(job_id) assert job handler = MailNotificationHandler() parent = handler.get_parent(job) context = handler.get_context(job, parent) html_content = Markup(toronado.from_string( render_template('listeners/mail/notification.html', **context) )) return render_template('debug/email.html', html_content=html_content)
def get_msg(self, builds): context = build_context_lib.get_collection_context(builds) if context['result'] == Result.passed: return None max_shown = current_app.config.get('MAX_SHOWN_ITEMS_PER_BUILD_MAIL', 3) context.update({ 'MAX_SHOWN_ITEMS_PER_BUILD': max_shown, 'showing_failing_tests_count': sum([min(b['failing_tests_count'], max_shown) for b in context['builds']]) }) recipients = self.get_collection_recipients(context) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup(toronado.from_string( render_template('listeners/mail/notification.html', **context) )) return msg
def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = filter_recipients(self.get_recipients(job)) if not recipients: return event = try_create( Event, where={"type": EventType.email, "item_id": job.build_id, "data": {"recipients": recipients}} ) if not event: # We've already sent out notifications for this build return context = self.get_context(job, parent) msg = Message( context["title"], recipients=recipients, extra_headers={"Reply-To": ", ".join(sanitize_address(r) for r in recipients)}, ) msg.body = render_template("listeners/mail/notification.txt", **context) msg.html = Markup(toronado.from_string(render_template("listeners/mail/notification.html", **context))) mail.send(msg)
def inline_css(html): return toronado.from_string(html)
def test_from_string(self): result = from_string(self.document) tree = etree.fromstring(result) self.assertInlines(tree)