コード例 #1
0
def view_letter_upload_as_preview(service_id, file_id):
    try:
        page = int(request.args.get('page'))
    except ValueError:
        abort(400)

    pdf_file, metadata = get_letter_pdf_and_metadata(service_id, file_id)
    invalid_pages = json.loads(metadata.get('invalid_pages', '[]'))

    if (metadata.get('message') == 'content-outside-printable-area'
            and page in invalid_pages):
        return TemplatePreview.from_invalid_pdf_file(pdf_file, page)
    else:
        return TemplatePreview.from_valid_pdf_file(pdf_file, page)
コード例 #2
0
def test_from_example_template_makes_request(mocker):
    request_mock = mocker.patch('app.template_previews.requests.post')
    template = {}
    filename = 'geo'

    TemplatePreview.from_example_template(template, filename)

    request_mock.assert_called_once_with(
        'http://localhost:9999/preview.png',
        headers={'Authorization': 'Token my-secret-key'},
        json={'values': None,
              'template': template,
              'filename': filename,
              'letter_contact_block': None}
    )
コード例 #3
0
def view_letter_template_preview(service_id, template_id, filetype):
    if filetype not in ('pdf', 'png'):
        abort(404)

    db_template = current_service.get_template(template_id)

    return TemplatePreview.from_database_object(db_template, filetype, page=request.args.get('page'))
コード例 #4
0
def letter_branding_preview_image(filename):
    template = {
        'subject':
        'An example letter',
        'content':
        ('Lorem Ipsum is simply dummy text of the printing and typesetting '
         'industry.\n\nLorem Ipsum has been the industry’s standard dummy '
         'text ever since the 1500s, when an unknown printer took a galley '
         'of type and scrambled it to make a type specimen book.\n\n'
         '# History\n\nIt has survived not only\n\n'
         '* five centuries\n'
         '* but also the leap into electronic typesetting\n\n'
         'It was popularised in the 1960s with the release of Letraset '
         'sheets containing Lorem Ipsum passages, and more recently with '
         'desktop publishing software like Aldus PageMaker including '
         'versions of Lorem Ipsum.\n\n'
         'The point of using Lorem Ipsum is that it has a more-or-less '
         'normal distribution of letters, as opposed to using ‘Content '
         'here, content here’, making it look like readable English.'),
        'template_type':
        'letter',
    }
    filename = None if filename == 'no-branding' else filename

    return TemplatePreview.from_example_template(template, filename)
コード例 #5
0
def test_from_example_template_makes_request(app_, mocker):
    request_mock = mocker.patch("app.template_previews.requests.post")
    template = {}
    filename = "geo"

    TemplatePreview.from_example_template(template, filename)

    request_mock.assert_called_once_with(
        "http://localhost:9999/preview.png",
        headers={"Authorization": "Token {}".format("dev-notify-secret-key")},
        json={
            "values": None,
            "template": template,
            "filename": filename,
            "letter_contact_block": None,
        },
    )
コード例 #6
0
def check_messages_preview(service_id, template_type, upload_id, filetype, row_index=2):
    if filetype not in ('pdf', 'png'):
        abort(404)

    template = _check_messages(
        service_id, template_type, upload_id, row_index, letters_as_pdf=True
    )['template']
    return TemplatePreview.from_utils_template(template, filetype)
コード例 #7
0
ファイル: send.py プロジェクト: duboisp/notification-admin
def check_notification_preview(service_id, template_id, filetype):
    if filetype == 'pdf':
        page = None
    elif filetype == 'png':
        page = request.args.get('page', 1)
    else:
        abort(404)

    template = _check_notification(
        service_id, template_id,
    )['template']
    return TemplatePreview.from_utils_template(template, filetype, page=page)
コード例 #8
0
ファイル: send.py プロジェクト: duboisp/notification-admin
def check_messages_preview(service_id, template_id, upload_id, filetype, row_index=2):
    if filetype == 'pdf':
        page = None
    elif filetype == 'png':
        page = request.args.get('page', 1)
    else:
        abort(404)

    template = _check_messages(
        service_id, template_id, upload_id, row_index, letters_as_pdf=True
    )['template']
    return TemplatePreview.from_utils_template(template, filetype, page=page)
コード例 #9
0
def check_notification_preview(service_id, template_id, filetype):
    if filetype == "pdf":
        page = None
    elif filetype == "png":
        page = request.args.get("page", 1)
    else:
        abort(404)

    template = _check_notification(
        service_id,
        template_id,
    )["template"]
    return TemplatePreview.from_utils_template(template, filetype, page=page)
コード例 #10
0
def test_from_valid_pdf_file_makes_request(mocker, page_number, expected_url):
    mocker.patch('app.template_previews.extract_page_from_pdf',
                 return_value=b'pdf page')
    request_mock = mocker.patch('app.template_previews.requests.post',
                                return_value=Mock(content='a',
                                                  status_code='b',
                                                  headers={'c': 'd'}))

    response = TemplatePreview.from_valid_pdf_file(b'pdf file', page_number)

    assert response == ('a', 'b', {'c': 'd'}.items())
    request_mock.assert_called_once_with(
        expected_url,
        data=base64.b64encode(b'pdf page').decode('utf-8'),
        headers={'Authorization': 'Token my-secret-key'},
    )
コード例 #11
0
def test_from_invalid_pdf_file_makes_request(mocker):
    mocker.patch('app.template_previews.extract_page_from_pdf',
                 return_value=b'pdf page')
    request_mock = mocker.patch('app.template_previews.requests.post',
                                return_value=Mock(content='a',
                                                  status_code='b',
                                                  headers={'c': 'd'}))

    response = TemplatePreview.from_invalid_pdf_file(b'pdf file', '1')

    assert response == ('a', 'b', {'c': 'd'}.items())
    request_mock.assert_called_once_with(
        'http://localhost:9999/precompiled/overlay.png?page_number=1',
        data=b'pdf page',
        headers={'Authorization': 'Token my-secret-key'},
    )
コード例 #12
0
def send_test_preview(service_id, template_id, filetype):

    if filetype not in ('pdf', 'png'):
        abort(404)

    db_template = service_api_client.get_service_template(service_id, template_id)['data']

    template = get_template(
        db_template,
        current_service,
        letter_preview_url=url_for(
            '.send_test_preview',
            service_id=service_id,
            template_id=template_id,
            filetype='png',
        ),
    )

    template.values = get_normalised_placeholders_from_session()

    return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page'))
コード例 #13
0
def send_test_preview(service_id, template_id, filetype):

    if filetype not in ('pdf', 'png'):
        abort(404)

    db_template = current_service.get_template_with_user_permission_or_403(template_id, current_user)

    template = get_template(
        db_template,
        current_service,
        letter_preview_url=url_for(
            'no_cookie.send_test_preview',
            service_id=service_id,
            template_id=template_id,
            filetype='png',
        ),
    )

    template.values = get_normalised_placeholders_from_session()

    return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page'))
コード例 #14
0
def view_letter_notification_as_preview(service_id, notification_id, filetype):

    if filetype not in ('pdf', 'png'):
        abort(404)

    notification = notification_api_client.get_notification(service_id, notification_id)
    notification['template'].update({'reply_to_text': notification['reply_to_text']})

    template = get_template(
        notification['template'],
        current_service,
        letter_preview_url=url_for(
            '.view_letter_notification_as_preview',
            service_id=service_id,
            notification_id=notification_id,
            filetype='png',
        ),
    )

    template.values = notification['personalisation']

    return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page'))
コード例 #15
0
def letter_branding_preview_image(filename):
    template = {
        "subject":
        "An example letter",
        "content":
        ("Lorem Ipsum is simply dummy text of the printing and typesetting "
         "industry.\n\nLorem Ipsum has been the industry’s standard dummy "
         "text ever since the 1500s, when an unknown printer took a galley "
         "of type and scrambled it to make a type specimen book.\n\n"
         "# History\n\nIt has survived not only\n\n"
         "* five centuries\n"
         "* but also the leap into electronic typesetting\n\n"
         "It was popularised in the 1960s with the release of Letraset "
         "sheets containing Lorem Ipsum passages, and more recently with "
         "desktop publishing software like Aldus PageMaker including "
         "versions of Lorem Ipsum.\n\n"
         "The point of using Lorem Ipsum is that it has a more-or-less "
         "normal distribution of letters, as opposed to using ‘Content "
         "here, content here’, making it look like readable English."),
    }
    filename = None if filename == "no-branding" else filename

    return TemplatePreview.from_example_template(template, filename)
コード例 #16
0
def view_template_version_preview(service_id, template_id, version, filetype):
    db_template = current_service.get_template(template_id, version=version)
    return TemplatePreview.from_database_object(db_template, filetype)
コード例 #17
0
def view_template_version_preview(service_id, template_id, version, filetype):
    db_template = service_api_client.get_service_template(
        service_id, template_id, version=version)['data']
    return TemplatePreview.from_database_object(db_template, filetype)