From c8cd3c2b7062ab7916b913e93d47e03881489fc8 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 12 May 2020 12:56:01 +0100 Subject: [PATCH] Return template name in job response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you’ve sent a bunch of jobs from the same contact list then a handy way to differentiate between them will be date sent, but also template name (in effect the message you sent). This commit extends the job response to include template name, using the same pattern as for template type. --- app/schemas.py | 4 ++++ tests/app/job/test_rest.py | 1 + 2 files changed, 5 insertions(+) diff --git a/app/schemas.py b/app/schemas.py index efa99e7d4..588c92ec0 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -380,9 +380,13 @@ class JobSchema(BaseSchema): service_name = fields.Nested( ServiceSchema, attribute="service", dump_to="service_name", only=["name"], dump_only=True) + template_name = fields.Method('get_template_name', dump_only=True) template_type = fields.Method('get_template_type', dump_only=True) contact_list_id = field_for(models.Job, 'contact_list_id') + def get_template_name(self, job): + return job.template.name + def get_template_type(self, job): return job.template.template_type diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index d6db5e917..0654ed6ff 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -718,6 +718,7 @@ def test_get_jobs(admin_request, sample_template): 'service_name': {'name': sample_template.service.name}, 'statistics': [], 'template': str(sample_template.id), + 'template_name': sample_template.name, 'template_type': 'sms', 'template_version': 1, 'updated_at': None,