Added fixes, displaying templates still needs to be fixed.

This commit is contained in:
Nicholas Staples
2016-01-22 11:14:56 +00:00
parent 64af225d2d
commit bb853ee95a
4 changed files with 22 additions and 12 deletions

View File

@@ -33,6 +33,10 @@ class TemplatesBrowsableItem(BrowsableItem):
def title(self):
return self._item['name']
@property
def type(self):
return self._item['template_type']
@property
def link(self):
return url_for(
@@ -47,3 +51,6 @@ class TemplatesBrowsableItem(BrowsableItem):
@property
def hint(self):
return "Some service template hint here"
def get_field(self, field):
return self._item.get(field, None)

View File

@@ -4,7 +4,8 @@ from flask_login import login_required
from app.main import main
from app.main.forms import TemplateForm
from app.main.dao.services_dao import get_service_by_id
from app.main.dao import templates_dao as dao
from app.main.dao import templates_dao as tdao
from app.main.dao import services_dao as sdao
from client.errors import HTTPError
@@ -12,7 +13,8 @@ from client.errors import HTTPError
@login_required
def manage_service_templates(service_id):
try:
templates = dao.get_service_templates(service_id)['data']
templates = tdao.get_service_templates(service_id)['data']
print(templates)
except HTTPError as e:
if e.status_code == 404:
abort(404)
@@ -21,14 +23,14 @@ def manage_service_templates(service_id):
return render_template(
'views/manage-templates.html',
service_id=service_id,
templates=templates)
templates=[tdao.TemplatesBrowsableItem(x) for x in templates])
@main.route("/services/<int:service_id>/templates/add", methods=['GET', 'POST'])
@login_required
def add_service_template(service_id):
try:
service = dao.get_service_by_id(service_id)['data']
service = sdao.get_service_by_id(service_id)['data']
except HTTPError as e:
if e.status_code == 404:
abort(404)
@@ -38,7 +40,7 @@ def add_service_template(service_id):
form = TemplateForm()
if form.validate_on_submit():
dao.insert_service_template(
tdao.insert_service_template(
form.name.data, form.template_type.data, form.content.data, service_id)
return redirect(url_for(
'.manage_service_templates', service_id=service_id))
@@ -53,7 +55,7 @@ def add_service_template(service_id):
@login_required
def edit_service_template(service_id, template_id):
try:
template = dao.get_service_template(service_id, template_id)['data']
template = tdao.get_service_template(service_id, template_id)['data']
except HTTPError as e:
if e.status_code == 404:
abort(404)
@@ -62,7 +64,7 @@ def edit_service_template(service_id, template_id):
form = TemplateForm(form_data=template)
if form.validate_on_submit():
dao.update_service_template(
tdao.update_service_template(
template_id, form.name.data, form.template_type.data,
form.content.data, service_id)
return redirect(url_for('.manage_service_templates', service_id=service_id))
@@ -79,7 +81,7 @@ def edit_service_template(service_id, template_id):
@login_required
def delete_service_template(service_id, template_id):
try:
template = dao.get_service_template(service_id, template_id)['data']
template = tdao.get_service_template(service_id, template_id)['data']
except HTTPError as e:
if e.status_code == 404:
abort(404)

View File

@@ -12,6 +12,7 @@ GOV.UK Notify | Edit template
<form method="post">
{{ textbox(form.name) }}
{{ textbox(form.template_type) }}
{{ textbox(form.content, highlight_tags=True) }}
{{ page_footer(
'Save',

View File

@@ -18,18 +18,18 @@ GOV.UK Notify | Manage templates
<a href="{{ url_for('.add_service_template', service_id=service_id) }}">Create new template</a>
{% for template in templates %}
{% if template.type == 'sms' %}
{% if template.get_field('template_type') == 'sms' %}
{{ sms_message(
template.content,
name=template.name,
edit_link=url_for('.edit_service_template', service_id=template.service, template_id=template.id)
edit_link=url_for('.edit_service_template', service_id=template.get_field('service'), template_id=template.get_field('id'))
) }}
{% elif template.type == 'email' %}
{% elif template.get_field('template_type') == 'email' %}
{{ email_message(
"template subject",
template.content,
name=template.name,
edit_link=url_for('.edit_service_template', service_id=template.service, template_id=template.id)
edit_link=url_for('.edit_service_template', service_id=template.get_field('service'), template_id=template.get_field('id'))
) }}
{% endif %}
{% endfor %}