Add a hint about how to use placeholders

Since placeholders (almost) work now, it’s worth telling people what the syntax
is.

This commit also removes the ‘template type’ picker, since you can only create
SMS templates at the moment. This will be revisited when we start looking at how
you add an email template.
This commit is contained in:
Chris Hill-Scott
2016-02-18 07:44:50 +00:00
parent 45cacd82d3
commit 426a23decd
8 changed files with 38 additions and 31 deletions

View File

@@ -40,6 +40,10 @@ a {
}
}
.form-control-1-1 {
width: 100%;
}
.form-control-5em {
width: 100%;

View File

@@ -49,6 +49,7 @@ $path: '/static/images/';
@import 'components/api-key';
@import 'views/job';
@import 'views/edit-template';
// TODO: break this up
@import 'app';

View File

@@ -0,0 +1,9 @@
.edit-template {
&-placeholder-hint {
display: block;
padding-top: 20px;
color: $secondary-text-colour;
}
}

View File

@@ -1,32 +1,23 @@
from flask import url_for, abort
from app import notifications_api_client
from app.utils import BrowsableItem
from notifications_python_client.errors import HTTPError
def insert_service_template(name, type_, content, service_id):
def insert_service_template(name, content, service_id):
return notifications_api_client.create_service_template(
name, type_, content, service_id)
name, 'sms', content, service_id)
def update_service_template(id_, name, type_, content, service_id):
def update_service_template(id_, name, content, service_id):
return notifications_api_client.update_service_template(
id_, name, type_, content, service_id)
id_, name, 'sms', content, service_id)
def get_service_templates(service_id):
return notifications_api_client.get_service_templates(service_id)
def get_service_templates_or_404(service_id):
try:
get_service_templates(service_id)
except HTTPError as e:
if e.status_code == 404:
abort(404)
else:
raise e
def get_service_template_or_404(service_id, template_id):
try:
return notifications_api_client.get_service_template(service_id, template_id)

View File

@@ -188,7 +188,6 @@ class TemplateForm(Form):
name = StringField(
u'Template name',
validators=[DataRequired(message="Template name cannot be empty")])
template_type = RadioField(u'Template type', choices=[('sms', 'SMS')])
template_content = TextAreaField(
u'Message',

View File

@@ -48,7 +48,7 @@ def add_service_template(service_id):
if form.validate_on_submit():
tdao.insert_service_template(
form.name.data, form.template_type.data, form.template_content.data, service_id)
form.name.data, form.template_content.data, service_id)
return redirect(url_for(
'.manage_service_templates', service_id=service_id))
return render_template(
@@ -67,7 +67,7 @@ def edit_service_template(service_id, template_id):
if form.validate_on_submit():
tdao.update_service_template(
template_id, form.name.data, form.template_type.data,
template_id, form.name.data,
form.template_content.data, service_id)
return redirect(url_for('.manage_service_templates', service_id=service_id))

View File

@@ -11,17 +11,22 @@
<h1 class="heading-large">{{ h1 }}</h1>
<form method="post">
{{ textbox(form.name) }}
<fieldset class="form-group">
<legend class="form-label">
Template type
</legend>
<label class="block-label" for="template_type">
<input type="radio" name="template_type" id="template_type" checked="checked" value="sms" />
Text message
</label>
</fieldset>
{{ textbox(form.template_content, highlight_tags=True) }}
<div class="grid-row">
<div class="column-two-thirds">
{{ textbox(form.name, width='1-1') }}
</div>
</div>
<div class="grid-row">
<div class="column-two-thirds">
{{ textbox(form.template_content, highlight_tags=True, width='1-1') }}
</div>
<div class="column-one-third">
<label for='template_content' class='edit-template-placeholder-hint'>
Add placeholders using double brackets, eg Your thing
is due on ((date))
</label>
</div>
</div>
{{ page_footer(
'Save',
delete_link=url_for('.delete_service_template', service_id=service_id, template_id=template_id) if template_id or None,

View File

@@ -58,12 +58,10 @@ def test_should_redirect_when_saving_a_template(app_,
service_id = str(uuid.uuid4())
template_id = 456
name = "new name"
type_ = "sms"
content = "template content"
data = {
'id': template_id,
'name': name,
'template_type': type_,
"template_content": content,
"service": service_id
}
@@ -76,7 +74,7 @@ def test_should_redirect_when_saving_a_template(app_,
assert response.location == url_for(
'.manage_service_templates', service_id=service_id, _external=True)
mock_update_service_template.assert_called_with(
template_id, name, type_, content, service_id)
template_id, name, 'sms', content, service_id)
def test_should_show_delete_template_page(app_,