Start to add template_version to jobs and notification
This commit is contained in:
Rebecca Law
2016-05-11 17:04:51 +01:00
parent ba874cfd43
commit f72f5aba05
6 changed files with 80 additions and 235 deletions

View File

@@ -143,7 +143,7 @@ def process_job(job_id):
dao_update_job(job)
template = Template(
dao_get_template_by_id(job.template_id).__dict__
dao_get_template_by_id(job.template_id, job.template_version).__dict__
)
for recipient, personalisation in RecipientCSV(
@@ -154,6 +154,7 @@ def process_job(job_id):
encrypted = encryption.encrypt({
'template': str(template.id),
'template_version': job.template_version,
'job': str(job.id),
'to': recipient,
'personalisation': {
@@ -219,7 +220,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
try:
template = Template(
dao_get_template_by_id(notification['template']).__dict__,
dao_get_template_by_id(notification['template'], notification['template_version']).__dict__,
values=notification.get('personalisation', {}),
prefix=service.name
)
@@ -228,6 +229,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
notification_db_object = Notification(
id=notification_id,
template_id=notification['template'],
template_version=notification['template_version'],
to=notification['to'],
service_id=service_id,
job_id=notification.get('job', None),

View File

@@ -14,6 +14,8 @@ from app.dao.services_dao import (
dao_fetch_service_by_id
)
from app.dao.templates_dao import (dao_get_template_by_id)
from app.schemas import job_schema
from app.celery.tasks import process_job
@@ -49,6 +51,8 @@ def create_job(service_id):
data.update({
"service": service_id
})
template = dao_get_template_by_id(data['template'])
data.update({"template_version": template.version})
job, errors = job_schema.load(data)
if errors:
return jsonify(result="error", message=errors), 400

View File

@@ -224,6 +224,7 @@ class Job(db.Model):
service = db.relationship('Service', backref=db.backref('jobs', lazy='dynamic'))
template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, unique=False)
template = db.relationship('Template', backref=db.backref('jobs', lazy='dynamic'))
template_version = db.Column(db.Integer, nullable=False)
created_at = db.Column(
db.DateTime,
index=False,
@@ -301,6 +302,7 @@ class Notification(db.Model):
service = db.relationship('Service')
template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, unique=False)
template = db.relationship('Template')
template_version = db.Column(db.Integer, nullable=False)
content_char_count = db.Column(db.Integer, nullable=True)
created_at = db.Column(
db.DateTime,