Beispiel #1
0
def get_back_link(service_id, template, step_index, placeholders=None):
    if step_index == 0:
        if should_skip_template_page(template.template_type):
            return url_for(
                '.choose_template',
                service_id=service_id,
            )
        else:
            return url_for(
                '.view_template',
                service_id=service_id,
                template_id=template.id,
            )

    if template.template_type == 'letter' and placeholders:
        # Make sure we’re not redirecting users to a page which will
        # just redirect them forwards again
        back_link_destination_step_index = next(
            (index for index, placeholder in reversed(
                list(enumerate(placeholders[:step_index]))) if placeholder
             not in Columns(PostalAddress('').as_personalisation)), 1)
        return get_back_link(service_id, template,
                             back_link_destination_step_index + 1)

    return url_for(
        'main.send_one_off_step',
        service_id=service_id,
        template_id=template.id,
        step_index=step_index - 1,
    )
Beispiel #2
0
def view_template(service_id, template_id):
    template = current_service.get_template(template_id)
    template_folder = current_service.get_template_folder(template['folder'])

    user_has_template_permission = current_user.has_template_folder_permission(
        template_folder)

    if should_skip_template_page(template['template_type']):
        return redirect(
            url_for('.send_one_off',
                    service_id=service_id,
                    template_id=template_id))

    page_count = get_page_count_for_letter(template)

    return render_template(
        'views/templates/template.html',
        template=get_template(
            template,
            current_service,
            letter_preview_url=url_for(
                'no_cookie.view_letter_template_preview',
                service_id=service_id,
                template_id=template_id,
                filetype='png',
            ),
            show_recipient=True,
            page_count=get_page_count_for_letter(template),
        ),
        template_postage=template["postage"],
        user_has_template_permission=user_has_template_permission,
        letter_too_long=is_letter_too_long(page_count),
        letter_max_pages=LETTER_MAX_PAGE_COUNT,
        page_count=page_count)
Beispiel #3
0
def get_back_link(service_id, template, step_index):
    if get_help_argument():
        # if we're on the check page, redirect back to the beginning. anywhere else, don't return the back link
        if request.endpoint == 'main.check_notification':
            return url_for('main.send_test',
                           service_id=service_id,
                           template_id=template.id,
                           help=get_help_argument())
        else:
            return None
    elif step_index == 0:
        if should_skip_template_page(template.template_type):
            return url_for(
                '.choose_template',
                service_id=service_id,
            )
        else:
            return url_for(
                '.view_template',
                service_id=service_id,
                template_id=template.id,
            )

    else:
        return url_for(
            'main.send_one_off_step',
            service_id=service_id,
            template_id=template.id,
            step_index=step_index - 1,
        )
Beispiel #4
0
def view_template(service_id, template_id):
    template = service_api_client.get_service_template(
        service_id, str(template_id))['data']
    if should_skip_template_page(template['template_type']):
        return redirect(
            url_for('.send_one_off',
                    service_id=service_id,
                    template_id=template_id))
    if template["template_type"] == "letter":
        letter_contact_details = service_api_client.get_letter_contacts(
            service_id)
        default_letter_contact_block_id = next(
            (x['id'] for x in letter_contact_details if x['is_default']), None)
    else:
        default_letter_contact_block_id = None
    return render_template(
        'views/templates/template.html',
        template=get_template(
            template,
            current_service,
            expand_emails=True,
            letter_preview_url=url_for(
                '.view_letter_template_preview',
                service_id=service_id,
                template_id=template_id,
                filetype='png',
            ),
            show_recipient=True,
            page_count=get_page_count_for_letter(template),
        ),
        default_letter_contact_block_id=default_letter_contact_block_id,
    )
Beispiel #5
0
def get_back_link(service_id, template, step_index):
    if get_help_argument():
        if request.endpoint == 'main.check_notification':
            return url_for(
                'main.send_test',
                service_id=service_id,
                template_id=template.id,
                help=get_help_argument()
            )
        else:
            if step_index == 0:
                return url_for(
                    'main.start_tour',
                    service_id=service_id,
                    template_id=template.id,
                )
            elif step_index > 0:
                return url_for(
                    'main.send_test_step',
                    service_id=service_id,
                    template_id=template.id,
                    step_index=step_index - 1,
                    help=2,
                )
    elif is_current_user_the_recipient() and step_index > 0:
        return url_for(
            'main.send_test_step',
            service_id=service_id,
            template_id=template.id,
            step_index=step_index - 1,
        )
    elif is_current_user_the_recipient() and step_index == 0:
        return url_for(
            'main.send_one_off_step',
            service_id=service_id,
            template_id=template.id,
            step_index=0,
        )
    elif step_index == 0:
        if should_skip_template_page(template.template_type):
            return url_for(
                '.choose_template',
                service_id=service_id,
            )
        else:
            return url_for(
                '.view_template',
                service_id=service_id,
                template_id=template.id,
            )
    else:
        return url_for(
            'main.send_one_off_step',
            service_id=service_id,
            template_id=template.id,
            step_index=step_index - 1,
        )
Beispiel #6
0
def view_template(service_id, template_id):
    template = current_service.get_template(template_id)
    template_folder = current_service.get_template_folder(template['folder'])

    user_has_template_permission = current_user.has_template_folder_permission(
        template_folder)

    if should_skip_template_page(template['template_type']):
        return redirect(
            url_for('.send_one_off',
                    service_id=service_id,
                    template_id=template_id))

    return render_template(
        'views/templates/template.html',
        template=get_email_preview_template(template, template_id, service_id),
        template_postage=template["postage"],
        user_has_template_permission=user_has_template_permission,
    )
Beispiel #7
0
def get_back_link(service_id, template, step_index, placeholders=None):
    if get_help_argument():
        # if we're on the check page, redirect back to the beginning. anywhere else, don't return the back link
        if request.endpoint == 'main.check_notification':
            return url_for('main.send_test',
                           service_id=service_id,
                           template_id=template.id,
                           help=get_help_argument())
        else:
            if step_index == 0:
                return url_for(
                    'main.start_tour',
                    service_id=service_id,
                    template_id=template.id,
                )
            elif step_index > 0:
                return url_for(
                    'main.send_test_step',
                    service_id=service_id,
                    template_id=template.id,
                    step_index=step_index - 1,
                    help=2,
                )
    elif step_index == 0:
        if should_skip_template_page(template.template_type):
            return url_for(
                '.choose_template',
                service_id=service_id,
            )
        else:
            return url_for(
                '.view_template',
                service_id=service_id,
                template_id=template.id,
            )
    elif is_current_user_the_recipient() and step_index > 1:
        return url_for(
            'main.send_test_step',
            service_id=service_id,
            template_id=template.id,
            step_index=step_index - 1,
        )
    elif is_current_user_the_recipient() and step_index == 1:
        return url_for(
            'main.send_one_off_step',
            service_id=service_id,
            template_id=template.id,
            step_index=0,
        )

    if template.template_type == 'letter' and placeholders:
        # Make sure we’re not redirecting users to a page which will
        # just redirect them forwards again
        back_link_destination_step_index = next(
            (index for index, placeholder in reversed(
                list(enumerate(placeholders[:step_index]))) if placeholder
             not in Columns(PostalAddress('').as_personalisation)), 1)
        return get_back_link(service_id, template,
                             back_link_destination_step_index + 1)

    return url_for(
        'main.send_one_off_step',
        service_id=service_id,
        template_id=template.id,
        step_index=step_index - 1,
    )