From 8464c67a3d9683774aed970e733a5197bedddd10 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 11 Oct 2016 10:35:33 +0100 Subject: [PATCH] move job statuses to job_api_client prevent code duplication and a good excuse to use set subtraction --- app/main/views/dashboard.py | 7 +------ app/main/views/jobs.py | 7 +------ app/notify_client/job_api_client.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 88b7f46af..5b9c6988d 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -116,12 +116,7 @@ def aggregate_usage(template_statistics): def get_dashboard_partials(service_id): # all but scheduled and cancelled - statuses_to_display = [ - 'pending', - 'in progress', - 'finished', - 'sending limits exceeded', - ] + statuses_to_display = job_api_client.JOB_STATUSES - {'scheduled', 'cancelled'} template_statistics = aggregate_usage( template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index bcb3e8fe9..9cdf91824 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -67,12 +67,7 @@ def _set_status_filters(filter_args): def view_jobs(service_id): page = int(request.args.get('page', 1)) # all but scheduled and cancelled - statuses_to_display = [ - 'pending', - 'in progress', - 'finished', - 'sending limits exceeded', - ] + statuses_to_display = job_api_client.JOB_STATUSES - {'scheduled', 'cancelled'} jobs_response = job_api_client.get_jobs(service_id, statuses=statuses_to_display, page=page) jobs = [ add_rate_to_job(job) for job in jobs_response['data'] diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index 0d0874bd6..4ec07bc8f 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -5,6 +5,16 @@ from app.notify_client import _attach_current_user class JobApiClient(BaseAPIClient): + + JOB_STATUSES = { + 'scheduled', + 'pending', + 'in progress', + 'finished', + 'cancelled', + 'sending limits exceeded', + } + def __init__(self): super().__init__("a", "b", "c")