Exemple #1
0
def letter_template():
    branding_style = request.args.get("branding_style")

    if branding_style == FieldWithNoneOption.NONE_OPTION_VALUE:
        branding_style = None

    if branding_style:
        filename = letter_branding_client.get_letter_branding(branding_style)["filename"]
    else:
        filename = "no-branding"

    template = {"subject": "", "content": ""}
    image_url = url_for("main.letter_branding_preview_image", filename=filename)

    template_image = str(
        LetterImageTemplate(
            template,
            image_url=image_url,
            page_count=1,
        )
    )

    resp = make_response(render_template("views/service-settings/letter-preview.html", template=template_image))

    resp.headers["X-Frame-Options"] = "SAMEORIGIN"
    return resp
Exemple #2
0
def letter_template():
    branding_style = request.args.get('branding_style')

    if branding_style == FieldWithNoneOption.NONE_OPTION_VALUE:
        branding_style = None

    if branding_style:
        filename = letter_branding_client.get_letter_branding(
            branding_style)['filename']
    else:
        filename = 'no-branding'

    template = {'subject': '', 'content': '', 'template_type': 'letter'}
    image_url = url_for('no_cookie.letter_branding_preview_image',
                        filename=filename)

    template_image = str(
        LetterImageTemplate(
            template,
            image_url=image_url,
            page_count=1,
        ))

    resp = make_response(
        render_template('views/service-settings/letter-preview.html',
                        template=template_image))

    resp.headers['X-Frame-Options'] = 'SAMEORIGIN'
    return resp
Exemple #3
0
def get_template(
    template,
    service,
    show_recipient=False,
    letter_preview_url=None,
    page_count=1,
    redact_missing_personalisation=False,
    email_reply_to=None,
    sms_sender=None,
):
    # Local Jinja support - add USE_LOCAL_JINJA_TEMPLATES=True to .env
    # Add a folder to the project root called 'jinja_templates' with copies from notification-utls repo of:
    # 'email_preview_template.jinja2'
    # 'sms_preview_template.jinja2'
    debug_template_path = path.dirname(
        path.abspath(__file__)) if os.environ.get(
            "USE_LOCAL_JINJA_TEMPLATES") == "True" else None

    if "email" == template["template_type"]:
        return EmailPreviewTemplate(
            template,
            from_name=service.name,
            from_address="{}@notifications.service.gov.uk".format(
                service.email_from),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
            reply_to=email_reply_to,
            jinja_path=debug_template_path,
            **get_email_logo_options(service),
        )
    if "sms" == template["template_type"]:
        return SMSPreviewTemplate(
            template,
            prefix=service.name,
            show_prefix=service.prefix_sms,
            sender=sms_sender,
            show_sender=bool(sms_sender),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
            jinja_path=debug_template_path,
        )
    if "letter" == template["template_type"]:
        if letter_preview_url:
            return LetterImageTemplate(
                template,
                image_url=letter_preview_url,
                page_count=int(page_count),
                contact_block=template["reply_to_text"],
                postage=template["postage"],
            )
        else:
            return LetterPreviewTemplate(
                template,
                contact_block=template["reply_to_text"],
                admin_base_url=current_app.config["ADMIN_BASE_URL"],
                redact_missing_personalisation=redact_missing_personalisation,
            )
def get_sample_template(template_type):
    if template_type == 'email':
        return EmailPreviewTemplate({'content': 'any', 'subject': '', 'template_type': 'email'})
    if template_type == 'sms':
        return SMSPreviewTemplate({'content': 'any', 'template_type': 'sms'})
    if template_type == 'letter':
        return LetterImageTemplate(
            {'content': 'any', 'subject': '', 'template_type': 'letter'}, postage='second', image_url='x', page_count=1
        )
def test_letter_image_renderer(jinja_template):
    str(LetterImageTemplate(
        {'content': '', 'subject': ''},
        image_url='http://example.com/endpoint.png',
        page_count=99,
    ))
    jinja_template.assert_called_once_with({
        'image_url': 'http://example.com/endpoint.png',
        'page_numbers': range(1, 100),
    })
Exemple #6
0
def test_letter_image_renderer_pagination(page_image_url):
    assert page_image_url in str(
        LetterImageTemplate(
            {
                'content': '',
                'subject': ''
            },
            image_url='http://example.com/endpoint.png',
            page_count=3,
        ))
def get_template(
    template,
    service,
    show_recipient=False,
    letter_preview_url=None,
    page_count=1,
    redact_missing_personalisation=False,
    email_reply_to=None,
    sms_sender=None,
):
    if 'email' == template['template_type']:
        return EmailPreviewTemplate(
            template,
            from_name=service.name,
            from_address='{}@notifications.service.gov.uk'.format(service.email_from),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
            reply_to=email_reply_to,
        )
    if 'sms' == template['template_type']:
        return SMSPreviewTemplate(
            template,
            prefix=service.name,
            show_prefix=service.prefix_sms,
            sender=sms_sender,
            show_sender=bool(sms_sender),
            show_recipient=show_recipient,
            redact_missing_personalisation=redact_missing_personalisation,
        )
    if 'letter' == template['template_type']:
        if letter_preview_url:
            return LetterImageTemplate(
                template,
                image_url=letter_preview_url,
                page_count=int(page_count),
                contact_block=template['reply_to_text'],
                postage=template['postage'],
            )
        else:
            return LetterPreviewTemplate(
                template,
                contact_block=template['reply_to_text'],
                admin_base_url=current_app.config['ADMIN_BASE_URL'],
                redact_missing_personalisation=redact_missing_personalisation,
            )
    if 'broadcast' == template['template_type']:
        return BroadcastPreviewTemplate(
            template,
        )
def get_sample_template(template_type):
    if template_type == 'email':
        return EmailPreviewTemplate({
            'content': 'any',
            'subject': '',
            'template_type': 'email'
        })
    if template_type == 'sms':
        return SMSPreviewTemplate({'content': 'any', 'template_type': 'sms'})
    if template_type == 'letter':
        return LetterImageTemplate({
            'content': 'any',
            'subject': '',
            'template_type': 'letter'
        })
def _sample_template(template_type, content='foo'):
    return {
        'email':
        EmailPreviewTemplate({
            'content': content,
            'subject': 'bar',
            'template_type': 'email'
        }),
        'sms':
        SMSMessageTemplate({
            'content': content,
            'template_type': 'sms'
        }),
        'letter':
        LetterImageTemplate(
            {
                'content': content,
                'subject': 'bar',
                'template_type': 'letter'
            },
            image_url='https://example.com',
            page_count=1,
        ),
    }.get(template_type)
        EmailPreviewTemplate(
            {"content": "((content))", "subject": "((subject))"},
        ),
        ['content', 'subject'],
    ),
    (
        LetterPreviewTemplate(
            {"content": "((content))", "subject": "((subject))"},
            contact_block='((contact_block))',
        ),
        ['content', 'subject', 'contact_block'],
    ),
    (
        LetterImageTemplate(
            {"content": "((content))", "subject": "((subject))"},
            contact_block='((contact_block))',
            image_url='http://example.com',
            page_count=99,
        ),
        ['content', 'subject', 'contact_block'],
    ),
])
def test_templates_extract_placeholders(
    template_instance,
    expected_placeholders,
):
    assert template_instance.placeholders == set(expected_placeholders)


@pytest.mark.parametrize('extra_args', [
    {
        'from_name': 'Example service'