Files
notifications-admin/app/main/dao/templates_dao.py
Chris Hill-Scott 2d55bb7ae2 Use Template to replace/highlight placeholders
This commit brings in the `Template` util, added here:
https://github.com/alphagov/notifications-utils/pull/1

It also does a fair bit of tidying up, which I’ve unfortunately squashed into
this one massive commit. The main change is moving 404 handling into the
templates dao, so that every view isn’t littered with `try: … except(HTTPError)`.

It also adds new features, in a prototypy sort of way, which are:
- download a prefilled example CSV
- show all the columns for your template on the 'check' page
2016-02-18 15:07:14 +00:00

72 lines
1.8 KiB
Python

from flask import url_for, abort
from app import notifications_api_client
from app.main.utils import BrowsableItem
def insert_service_template(name, type_, content, service_id):
return notifications_api_client.create_service_template(
name, type_, content, service_id)
def update_service_template(id_, name, type_, content, service_id):
return notifications_api_client.update_service_template(
id_, name, type_, 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)
except HTTPError as e:
if e.status_code == 404:
abort(404)
else:
raise e
def delete_service_template(service_id, template_id):
return notifications_api_client.delete_service_template(
service_id, template_id)
class TemplatesBrowsableItem(BrowsableItem):
@property
def title(self):
return self._item['name']
@property
def type(self):
return self._item['template_type']
@property
def link(self):
return url_for(
'main.edit_service_template',
service_id=self._item['service'],
template_id=self._item['id'])
@property
def destructive(self):
return False
@property
def hint(self):
return "Some service template hint here"
def get_field(self, field):
return self._item.get(field, None)