コード例 #1
0
def test_random_input(document, remove_style_tags, base_url,
                      load_remote_stylesheets):
    with suppress(ValueError):
        inliner = css_inline.CSSInliner(
            remove_style_tags=remove_style_tags,
            base_url=base_url,
            load_remote_stylesheets=load_remote_stylesheets)
        inliner.inline(document)
コード例 #2
0
    def render(self, plain_body: str, plain_signature: str, subject: str, order, position) -> str:
        body_md = markdown_compile_email(plain_body)
        htmlctx = {
            'site': settings.PRETIX_INSTANCE_NAME,
            'site_url': settings.SITE_URL,
            'body': body_md,
            'subject': str(subject),
            'color': settings.PRETIX_PRIMARY_COLOR,
            'rtl': get_language() in settings.LANGUAGES_RTL or get_language().split('-')[0] in settings.LANGUAGES_RTL,
        }
        if self.organizer:
            htmlctx['organizer'] = self.organizer

        if self.event:
            htmlctx['event'] = self.event
            htmlctx['color'] = self.event.settings.primary_color

        if plain_signature:
            signature_md = plain_signature.replace('\n', '<br>\n')
            signature_md = markdown_compile_email(signature_md)
            htmlctx['signature'] = signature_md

        if order:
            htmlctx['order'] = order
            positions = list(order.positions.select_related(
                'item', 'variation', 'subevent', 'addon_to'
            ).annotate(
                has_addons=Count('addons')
            ))
            htmlctx['cart'] = [(k, list(v)) for k, v in groupby(
                sorted(
                    positions,
                    key=lambda op: (
                        (op.addon_to.positionid if op.addon_to_id else op.positionid),
                        op.positionid
                    )
                ),
                key=lambda op: (
                    op.item,
                    op.variation,
                    op.subevent,
                    op.attendee_name,
                    op.addon_to_id,
                    (op.pk if op.has_addons else None)
                )
            )]

        if position:
            htmlctx['position'] = position
            htmlctx['ev'] = position.subevent or self.event

        tpl = get_template(self.template_name)
        body_html = tpl.render(htmlctx)

        inliner = css_inline.CSSInliner(remove_style_tags=True)
        body_html = inliner.inline(body_html)

        return body_html
コード例 #3
0
def send_notification_mail(notification: Notification, user: User):
    ctx = {
        'site':
        settings.PRETIX_INSTANCE_NAME,
        'site_url':
        settings.SITE_URL,
        'color':
        settings.PRETIX_PRIMARY_COLOR,
        'notification':
        notification,
        'settings_url':
        build_absolute_uri('control:user.settings.notifications', ),
        'disable_url':
        build_absolute_uri('control:user.settings.notifications.off',
                           kwargs={
                               'token': user.notifications_token,
                               'id': user.pk
                           })
    }

    tpl_html = get_template('pretixbase/email/notification.html')

    body_html = tpl_html.render(ctx)
    inliner = css_inline.CSSInliner(remove_style_tags=True)
    body_html = inliner.inline(body_html)

    tpl_plain = get_template('pretixbase/email/notification.txt')
    body_plain = tpl_plain.render(ctx)

    mail_send_task.apply_async(
        kwargs={
            'to': [user.email],
            'subject':
            '[{}] {}: {}'.format(
                settings.PRETIX_INSTANCE_NAME,
                notification.event.settings.mail_prefix
                or notification.event.slug.upper(), notification.title),
            'body':
            body_plain,
            'html':
            body_html,
            'sender':
            settings.MAIL_FROM_NOTIFICATIONS,
            'headers': {},
            'user':
            user.pk
        })
コード例 #4
0
def test_invalid_base_url():
    with pytest.raises(ValueError):
        css_inline.CSSInliner(base_url="foo")
コード例 #5
0
SAMPLE_STYLE = """h1, h2 { color:red; }
strong { text-decoration:none }
p { font-size:2px }
p.footer { font-size: 1px}"""
SAMPLE_INLINED = """<h1 style="color:red;">Big Text</h1>
<p style="font-size:2px ;"><strong style="text-decoration:none ;">Yes!</strong></p>
<p class="footer" style="font-size: 1px;">Foot notes</p>"""


@pytest.mark.parametrize(
    "func",
    (
        lambda html, **kwargs: css_inline.inline(html, **kwargs),
        lambda html, **kwargs: css_inline.inline_many([html], **kwargs),
        lambda html, **kwargs: css_inline.CSSInliner(**kwargs).inline(html),
        lambda html, **kwargs: css_inline.CSSInliner(**kwargs).inline_many([html]),
    ),
)
@pytest.mark.parametrize(
    "kwargs, expected",
    (
        ({}, make_html(SAMPLE_STYLE, SAMPLE_INLINED)),
        (
            {"remove_style_tags": True},
            "<html><head><title>Test</title></head><body>{body}</body></html>".format(
                body=SAMPLE_INLINED
            ),
        ),
    ),
)
コード例 #6
0
 def render(self):
     inliner = css_inline.CSSInliner(extra_css=self.css)
     inlined = inliner.inline(self.html)
     return inlined