From 426a23decd725cef7f909cc7a7ceb8f77fce9da4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 18 Feb 2016 07:44:50 +0000 Subject: [PATCH] Add a hint about how to use placeholders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/assets/stylesheets/app.scss | 4 +++ app/assets/stylesheets/main.scss | 1 + .../stylesheets/views/edit-template.scss | 9 +++++++ app/main/dao/templates_dao.py | 19 ++++--------- app/main/forms.py | 1 - app/main/views/templates.py | 4 +-- app/templates/views/edit-template.html | 27 +++++++++++-------- tests/app/main/views/test_templates.py | 4 +-- 8 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 app/assets/stylesheets/views/edit-template.scss diff --git a/app/assets/stylesheets/app.scss b/app/assets/stylesheets/app.scss index dcb2a9f2b..e4a629217 100644 --- a/app/assets/stylesheets/app.scss +++ b/app/assets/stylesheets/app.scss @@ -40,6 +40,10 @@ a { } } +.form-control-1-1 { + width: 100%; +} + .form-control-5em { width: 100%; diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index f04d61fce..eb420be44 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -49,6 +49,7 @@ $path: '/static/images/'; @import 'components/api-key'; @import 'views/job'; +@import 'views/edit-template'; // TODO: break this up @import 'app'; diff --git a/app/assets/stylesheets/views/edit-template.scss b/app/assets/stylesheets/views/edit-template.scss new file mode 100644 index 000000000..3635b067f --- /dev/null +++ b/app/assets/stylesheets/views/edit-template.scss @@ -0,0 +1,9 @@ +.edit-template { + + &-placeholder-hint { + display: block; + padding-top: 20px; + color: $secondary-text-colour; + } + +} diff --git a/app/main/dao/templates_dao.py b/app/main/dao/templates_dao.py index 032c45fbf..d34f2b187 100644 --- a/app/main/dao/templates_dao.py +++ b/app/main/dao/templates_dao.py @@ -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) diff --git a/app/main/forms.py b/app/main/forms.py index cf1aa76c8..ddab3fe01 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -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', diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 0b3f492ff..a8453f9e5 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -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)) diff --git a/app/templates/views/edit-template.html b/app/templates/views/edit-template.html index ae3d5005e..2563dd81e 100644 --- a/app/templates/views/edit-template.html +++ b/app/templates/views/edit-template.html @@ -11,17 +11,22 @@

{{ h1 }}

- {{ textbox(form.name) }} -
- - Template type - - -
- {{ textbox(form.template_content, highlight_tags=True) }} +
+
+ {{ textbox(form.name, width='1-1') }} +
+
+
+
+ {{ textbox(form.template_content, highlight_tags=True, width='1-1') }} +
+
+ +
+
{{ page_footer( 'Save', delete_link=url_for('.delete_service_template', service_id=service_id, template_id=template_id) if template_id or None, diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 47af74f9f..3319f1468 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -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_,