Show one field at a time on send yourself a test

The send yourself a test feature is useful for two things:
- constructing an email/text message/letter without uploading a CSV file
- seeing what the thing your going to send will look like (either by
  getting it in your inbox or downloading the PDF)
- learning the concept of placeholders, ie understanding they’re thing
  that gets populated with _stuff_

The problem we’re seeing is that the current UI breaks when a template
has a lot of placeholders. This is especially apparent with letter
templates, which have a minimum of 7 placeholders by virtue of the
address.

The idea behind having the form fields side-by-side was to help people
understand the relationship between their spreadsheet columns and the
placeholders. But this means that the page was doing a lot of work,
trying to teach:
- replacement of placeholders
- link between placeholders and spreadsheet columns

The latter is better explained by the example spreadsheet shown on the
upload page. So it can safely be removed from the send yourself a test
page – in other words the fields don’t need to be shown side by side.

Showing them one-at-a-time works well because:
- it’s really obvious, even on first use, what the page is asking you to
  do
- as your step through each placeholder, you see the message build up
  with the data you’ve entered – you’re learning how replacement of
  placeholders works by repetition

This also means adding a matching endpoint for viewing each step of
making the test letter as a PDF/PNG because we can’t reuse the view of
the template without any placeholders filled any more.
This commit is contained in:
Chris Hill-Scott
2017-05-04 09:30:55 +01:00
parent eb7b8631b6
commit 8c03feb334
6 changed files with 466 additions and 67 deletions

View File

@@ -1,6 +1,6 @@
import re
import pytz
from flask_login import current_user
from flask_wtf import Form
from datetime import datetime, timedelta
@@ -619,3 +619,26 @@ class ChooseTemplateType(Form):
class SearchTemplatesForm(Form):
search = SearchField('Search by name')
class PlaceholderForm(Form):
pass
def get_placeholder_form_instance(
placeholder_name,
dict_to_populate_from,
optional_placeholder=False
):
PlaceholderForm.placeholder_value = StringField(
placeholder_name,
validators=[
DataRequired(message='Cant be empty')
] if not optional_placeholder else []
)
return PlaceholderForm(
placeholder_value=dict_to_populate_from.get(placeholder_name, '')
)