add new endpoints for one-off flow

rather than creating a job, after entering the placeholders, you now
send a single notification. This means we don't clog up s3 by creating
lots of one line CSV files.
This commit is contained in:
Leo Hemsted
2017-06-23 15:02:20 +01:00
parent 16df91766f
commit 40f805c230
2 changed files with 94 additions and 2 deletions

View File

@@ -225,7 +225,11 @@ def send_test_step(service_id, template_id, step_index):
current_placeholder = placeholders[step_index]
except IndexError:
if all_placeholders_in_session(placeholders):
return make_and_upload_csv_file(service_id, template)
return redirect(url_for(
'main.send_notification',
service_id=service_id,
template_id=template_id,
))
return redirect(url_for(
{
'main.send_test_step': '.send_test',
@@ -248,7 +252,11 @@ def send_test_step(service_id, template_id, step_index):
session['send_test_values'][current_placeholder] = form.placeholder_value.data
if all_placeholders_in_session(placeholders):
return make_and_upload_csv_file(service_id, template)
return redirect(url_for(
'main.send_notification',
service_id=service_id,
template_id=template_id,
))
return redirect(url_for(
request.endpoint,
@@ -567,3 +575,53 @@ def get_back_link(service_id, template_id, step_index):
template_id=template_id,
step_index=step_index - 1,
)
@main.route("/services/<service_id>/template/<template_id>/notification/check", methods=['GET'])
@login_required
@user_has_permissions('manage_templates')
def check_notification(service_id, template_id):
# go back to start of process
back_link = get_back_link(service_id, template_id, 0)
db_template = service_api_client.get_service_template(service_id, template_id)['data']
template = get_template(
db_template,
current_service,
show_recipient=True,
letter_preview_url='FUCK WHAT DO I DO HERE'
)
return render_template(
'views/notifications/check.html',
template=template,
back_link=back_link,
help=get_help_argument(),
)
@main.route("/services/<service_id>/template/<template_id>/notification/check", methods=['POST'])
@login_required
@user_has_permissions('manage_templates')
def send_notification(service_id, template_id):
if 'send_test_values' not in session.keys():
return redirect(url_for(
'.send_one_off',
service_id=service_id,
template_id=template_id,
))
noti = notification_api_client.send_notification(
service_id,
template_id=template_id,
recipient=next(x for x in session['send_test_values'].values()),
personalisation=None
)
session.pop('send_test_values')
return redirect(url_for(
'.view_notification',
service_id=service_id,
notification_id=noti['id']
))

View File

@@ -0,0 +1,34 @@
{% 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/file-upload.html" import file_upload %} -->
<!-- {% from "components/page-footer.html" import page_footer %} -->
{% from "components/radios.html" import radio_select %}
{% from "components/message-count-label.html" import message_count_label %}
{% block service_page_title %}
{{ "Error" if errors else "Preview" }}
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
Preview of {{ template.name }}
</h1>
{{ template|string }}
<div class="bottom-gutter-3-2">
<form method="post" enctype="multipart/form-data" action="{{url_for('main.send_notification', service_id=current_service.id, template_id=template.id)}}" class='page-footer'>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="help" value="{{ '3' if help else 0 }}" />
{% if template.template_type != 'letter' or not request.args.from_test %}
<input type="submit" class="button" value="Send 1 {{ message_count_label(1, template.template_type, suffix='') }}" />
{% else %}
<a href="{{ url_for('main.check_messages_preview', service_id=current_service.id, template_type=template.template_type, upload_id=upload_id, filetype='pdf') }}" download="download" class="button">Download as a printable PDF</a>
{% endif %}
<a href="{{ back_link }}" class="page-footer-back-link">Back</a>
</form>
</div>
{% endblock %}