Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
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
Exemple #4
0
    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
Exemple #5
0
    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)
Exemple #6
0
    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
Exemple #7
0
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)
Exemple #8
0
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)
Exemple #9
0
    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)
Exemple #10
0
    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
Exemple #11
0
    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)
Exemple #12
0
def inline_css(html):
    return toronado.from_string(html)
Exemple #13
0
def inline_css(html):
    return toronado.from_string(html)
Exemple #14
0
 def test_from_string(self):
     result = from_string(self.document)
     tree = etree.fromstring(result)
     self.assertInlines(tree)
Exemple #15
0
 def test_from_string(self):
     result = from_string(self.document)
     tree = etree.fromstring(result)
     self.assertInlines(tree)