mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 16:39:49 -04:00
inital preview page
This commit is contained in:
@@ -13,6 +13,7 @@ from notifications_utils.recipients import RecipientCSV, first_column_headings
|
|||||||
from notifications_utils.sanitise_text import SanitiseASCII
|
from notifications_utils.sanitise_text import SanitiseASCII
|
||||||
from xlrd.biffh import XLRDError
|
from xlrd.biffh import XLRDError
|
||||||
from xlrd.xldate import XLDateError
|
from xlrd.xldate import XLDateError
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
from app import (
|
from app import (
|
||||||
current_service,
|
current_service,
|
||||||
@@ -563,6 +564,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
|||||||
sent_previously=job_api_client.has_sent_previously(
|
sent_previously=job_api_client.has_sent_previously(
|
||||||
service_id, template.id, db_template["version"], original_file_name
|
service_id, template.id, db_template["version"], original_file_name
|
||||||
),
|
),
|
||||||
|
template_id=template_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -606,17 +608,18 @@ def check_messages(service_id, template_id, upload_id, row_index=2):
|
|||||||
metadata_kwargs["sender_id"] = session["sender_id"]
|
metadata_kwargs["sender_id"] = session["sender_id"]
|
||||||
|
|
||||||
set_metadata_on_csv_upload(service_id, upload_id, **metadata_kwargs)
|
set_metadata_on_csv_upload(service_id, upload_id, **metadata_kwargs)
|
||||||
|
session['scheduled_for']=request.form.get("scheduled_for", "")
|
||||||
return render_template("views/check/ok.html", **data)
|
return render_template("views/check/ok.html", **data)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<uuid:service_id>/start-job/<uuid:upload_id>", methods=["POST"])
|
@main.route("/services/<uuid:service_id>/start-job/<uuid:upload_id>", methods=["POST"])
|
||||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||||
def start_job(service_id, upload_id):
|
def start_job(service_id, upload_id):
|
||||||
|
scheduled_for = session.pop('scheduled_for', None)
|
||||||
job_api_client.create_job(
|
job_api_client.create_job(
|
||||||
upload_id,
|
upload_id,
|
||||||
service_id,
|
service_id,
|
||||||
scheduled_for=request.form.get("scheduled_for", ""),
|
scheduled_for=scheduled_for,
|
||||||
)
|
)
|
||||||
|
|
||||||
session.pop("sender_id", None)
|
session.pop("sender_id", None)
|
||||||
@@ -630,6 +633,54 @@ def start_job(service_id, upload_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route(
|
||||||
|
"/services/<uuid:service_id>/<uuid:template_id>/check/<uuid:upload_id>/preview",
|
||||||
|
methods=["POST"],
|
||||||
|
)
|
||||||
|
@main.route(
|
||||||
|
"/services/<uuid:service_id>/<uuid:template_id>/check/<uuid:upload_id>/row-<int:row_index>/preview",
|
||||||
|
methods=["POST"],
|
||||||
|
)
|
||||||
|
@main.route("/services/<uuid:service_id>/preview-job/<uuid:upload_id>", methods=["POST"])
|
||||||
|
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||||
|
def preview_job(service_id, template_id, upload_id, row_index=2):
|
||||||
|
# Store form data in session temporarily
|
||||||
|
session['scheduled_for'] = request.form.get('scheduled_for', 'Not specified')
|
||||||
|
# session.pop("sender_id", None)
|
||||||
|
data = _check_messages(service_id, template_id, upload_id, row_index)
|
||||||
|
data["allowed_file_extensions"] = Spreadsheet.ALLOWED_FILE_EXTENSIONS
|
||||||
|
|
||||||
|
if (
|
||||||
|
data["recipients"].too_many_rows
|
||||||
|
or not data["count_of_recipients"]
|
||||||
|
or not data["recipients"].has_recipient_columns
|
||||||
|
or data["recipients"].duplicate_recipient_column_headers
|
||||||
|
or data["recipients"].missing_column_headers
|
||||||
|
or data["sent_previously"]
|
||||||
|
):
|
||||||
|
return render_template("views/check/column-errors.html", **data)
|
||||||
|
|
||||||
|
if data["row_errors"]:
|
||||||
|
return render_template("views/check/row-errors.html", **data)
|
||||||
|
|
||||||
|
if data["errors"]:
|
||||||
|
return render_template("views/check/column-errors.html", **data)
|
||||||
|
|
||||||
|
metadata_kwargs = {
|
||||||
|
"notification_count": data["count_of_recipients"],
|
||||||
|
"template_id": template_id,
|
||||||
|
"valid": True,
|
||||||
|
"original_file_name": data.get("original_file_name", ""),
|
||||||
|
}
|
||||||
|
|
||||||
|
if session.get("sender_id"):
|
||||||
|
metadata_kwargs["sender_id"] = session["sender_id"]
|
||||||
|
|
||||||
|
set_metadata_on_csv_upload(service_id, upload_id, **metadata_kwargs)
|
||||||
|
|
||||||
|
return render_template('views/check/preview.html', data=session['scheduled_for'], **data)
|
||||||
|
|
||||||
|
|
||||||
def fields_to_fill_in(template, prefill_current_user=False):
|
def fields_to_fill_in(template, prefill_current_user=False):
|
||||||
if not prefill_current_user:
|
if not prefill_current_user:
|
||||||
return first_column_headings[template.template_type] + list(
|
return first_column_headings[template.template_type] + list(
|
||||||
|
|||||||
@@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
{% block maincolumn_content %}
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
{{ page_header('Preview of {}'.format(template.name)) }}
|
{{ page_header('Select delivery time') }}
|
||||||
|
|
||||||
{{ template|string }}
|
{{ template|string }}
|
||||||
<div class="bottom-gutter-3-2">
|
<div class="bottom-gutter-3-2">
|
||||||
<form method="post" enctype="multipart/form-data" action="{{url_for('main.start_job', service_id=current_service.id, upload_id=upload_id)}}" class='page-footer'>
|
<form method="post" enctype="multipart/form-data" action="{{url_for('main.preview_job', service_id=current_service.id, template_id=template_id, upload_id=upload_id)}}" class='page-footer'>
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
{% if choose_time_form %}
|
{% if choose_time_form %}
|
||||||
{{ choose_time_form.scheduled_for(param_extensions={
|
{{ choose_time_form.scheduled_for(param_extensions={
|
||||||
@@ -36,56 +36,55 @@
|
|||||||
}) }}
|
}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not request.args.from_test %}
|
||||||
|
<h2 class="font-body-lg">Send list</h2>
|
||||||
|
<h3 id="{{ file_contents_header_id }}">{{ original_file_name }}</h3>
|
||||||
|
{% endif %}
|
||||||
{% set button_text %}
|
{% set button_text %}
|
||||||
Send {{ count_of_recipients|message_count(template.template_type) }}
|
Preview send
|
||||||
|
<!-- {{ count_of_recipients|message_count(template.template_type) }} -->
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{{ usaButton({ "text": button_text }) }}
|
{{ usaButton({ "text": button_text }) }}
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if not request.args.from_test %}
|
<!-- <div class="fullscreen-content" data-module="fullscreen-table">
|
||||||
|
{% call(item, row_number) list_table(
|
||||||
<h2 class="font-body-lg" id="{{ file_contents_header_id }}">{{ original_file_name }}</h2>
|
recipients.displayed_rows,
|
||||||
|
caption=original_file_name,
|
||||||
<div class="fullscreen-content" data-module="fullscreen-table">
|
caption_visible=False,
|
||||||
{% call(item, row_number) list_table(
|
field_headings=[
|
||||||
recipients.displayed_rows,
|
'<span class="usa-sr-only">Row in file</span><span aria-hidden="true">1</span>'|safe
|
||||||
caption=original_file_name,
|
] + recipients.column_headers
|
||||||
caption_visible=False,
|
) %}
|
||||||
field_headings=[
|
{% call index_field() %}
|
||||||
'<span class="usa-sr-only">Row in file</span><span aria-hidden="true">1</span>'|safe
|
<span>
|
||||||
] + recipients.column_headers
|
{% if (item.index + 2) == preview_row %}
|
||||||
) %}
|
{{ item.index + 2 }}
|
||||||
{% call index_field() %}
|
|
||||||
<span>
|
|
||||||
{% if (item.index + 2) == preview_row %}
|
|
||||||
{{ item.index + 2 }}
|
|
||||||
{% else %}
|
|
||||||
<a class="usa-link" href="{{ url_for('.check_messages', service_id=current_service.id, template_id=template.id, upload_id=upload_id, row_index=(item.index + 2), original_file_name=original_file_name) }}">{{ item.index + 2 }}</a>
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
{% endcall %}
|
|
||||||
{% for column in recipients.column_headers %}
|
|
||||||
{% if item[column].ignore %}
|
|
||||||
{{ text_field(item[column].data or '', status='default') }}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ text_field(item[column].data or '') }}
|
<a class="usa-link" href="{{ url_for('.check_messages', service_id=current_service.id, template_id=template.id, upload_id=upload_id, row_index=(item.index + 2), original_file_name=original_file_name) }}">{{ item.index + 2 }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
</span>
|
||||||
{% if item[None].data %}
|
|
||||||
{% for column in item[None].data %}
|
|
||||||
{{ text_field(column, status='default') }}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
</div>
|
{% for column in recipients.column_headers %}
|
||||||
|
{% if item[column].ignore %}
|
||||||
|
{{ text_field(item[column].data or '', status='default') }}
|
||||||
|
{% else %}
|
||||||
|
{{ text_field(item[column].data or '') }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if item[None].data %}
|
||||||
|
{% for column in item[None].data %}
|
||||||
|
{{ text_field(column, status='default') }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endcall %}
|
||||||
|
</div> -->
|
||||||
|
|
||||||
{% endif %}
|
<!-- {% if count_of_displayed_recipients < count_of_recipients %}
|
||||||
|
|
||||||
{% if count_of_displayed_recipients < count_of_recipients %}
|
|
||||||
<p class="table-show-more-link">
|
<p class="table-show-more-link">
|
||||||
Only showing the first {{ count_of_displayed_recipients }} rows
|
Only showing the first {{ count_of_displayed_recipients }} rows
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %} -->
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
96
app/templates/views/check/preview.html
Normal file
96
app/templates/views/check/preview.html
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
{% extends "withnav_template.html" %}
|
||||||
|
{% from "components/banner.html" import banner_wrapper %}
|
||||||
|
{% from "components/table.html" import list_table, field, text_field, index_field, hidden_field_heading %}
|
||||||
|
{% from "components/page-header.html" import page_header %}
|
||||||
|
{% from "components/components/button/macro.njk" import usaButton %}
|
||||||
|
{% from "components/components/skip-link/macro.njk" import usaSkipLink %}
|
||||||
|
{% from "components/components/back-link/macro.njk" import usaBackLink %}
|
||||||
|
|
||||||
|
{% set file_contents_header_id = 'file-preview' %}
|
||||||
|
|
||||||
|
{% block service_page_title %}
|
||||||
|
{{ "Preview of {}".format(template.name) }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block backLink %}
|
||||||
|
{{ usaBackLink({ "href": back_link }) }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
|
{{ page_header('Send messages') }}
|
||||||
|
<h2 id="{{ file_contents_header_id }}">Message</h2>
|
||||||
|
{{ template|string }}
|
||||||
|
<div class="bottom-gutter-3-2">
|
||||||
|
<form method="post" enctype="multipart/form-data" action="{{url_for('main.start_job', service_id=current_service.id, upload_id=upload_id)}}" class='page-footer'>
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
<!-- {% if choose_time_form %}
|
||||||
|
{{ choose_time_form.scheduled_for(param_extensions={
|
||||||
|
'formGroup': {'classes': 'bottom-gutter-2-3'},
|
||||||
|
'attributes': {
|
||||||
|
'data-module': 'radio-select',
|
||||||
|
'data-categories': choose_time_form.scheduled_for.categories|join(','),
|
||||||
|
'data-show-now-as-default': 'true'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
{% endif %} -->
|
||||||
|
{% if not request.args.from_test %}
|
||||||
|
|
||||||
|
<h2 class="font-body-lg">Preview list</h2>
|
||||||
|
|
||||||
|
<ul class="usa-icon-list">
|
||||||
|
<li class="usa-icon-list__item">
|
||||||
|
<div class="usa-icon-list__icon" >
|
||||||
|
<img src="{{ url_for('static', filename='img/material-icons/description.svg') }}" alt="Description Icon">
|
||||||
|
</div>
|
||||||
|
<div class="usa-icon-list__content">
|
||||||
|
<h3 id="{{ file_contents_header_id }}">{{ original_file_name }}</h3>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{% call(item, row_number) list_table(
|
||||||
|
recipients.displayed_rows,
|
||||||
|
caption=original_file_name,
|
||||||
|
caption_visible=False,
|
||||||
|
field_headings=recipients.column_headers
|
||||||
|
) %}
|
||||||
|
{% for column in recipients.column_headers %}
|
||||||
|
{% if item[column].ignore %}
|
||||||
|
{{ text_field(item[column].data or '', status='default') }}
|
||||||
|
{% else %}
|
||||||
|
{{ text_field(item[column].data or '') }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if item[None].data %}
|
||||||
|
{% for column in item[None].data %}
|
||||||
|
{{ text_field(column, status='default') }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endcall %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
<p>The service be charged 10 message parts for a total of 20 messages when this batch it sent
|
||||||
|
There are 480 of 500 messages remaining in your service</p>
|
||||||
|
<h3>Does everything look good?</h3>
|
||||||
|
{% set button_text %}
|
||||||
|
Send
|
||||||
|
<!-- {{ count_of_recipients|message_count(template.template_type) }} -->
|
||||||
|
{% endset %}
|
||||||
|
{{ usaButton({ "text": button_text }) }}
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- {% if count_of_displayed_recipients < count_of_recipients %}
|
||||||
|
<p class="table-show-more-link">
|
||||||
|
Only showing the first {{ count_of_displayed_recipients }} rows
|
||||||
|
</p>
|
||||||
|
{% endif %} -->
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user