From 340cb33fdd6589ef0cdb0af3f453fcaa72d131c4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 8 Jan 2020 16:23:43 +0000 Subject: [PATCH] =?UTF-8?q?Refactor=20=E2=80=98finished=E2=80=99=20to=20th?= =?UTF-8?q?e=20model=20layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By moving it from the view we reduce the complexity of the methods in the view layer, so it’s easier to see what they do. This also renames the variable `finished` to the property `processing_finished` to disambiguate from the `job_status` field in the JSON, which can also have a value of `finished`. --- app/main/views/jobs.py | 4 ---- app/models/job.py | 7 +++++-- app/templates/partials/jobs/notifications.html | 2 +- app/templates/views/jobs/job.html | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 42f0d7818..77db681a7 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -77,9 +77,6 @@ def view_job(service_id, job_id): filter_args = parse_filter_args(request.args) filter_args['status'] = set_status_filters(filter_args) - total_notifications = job.notification_count - processed_notifications = job.notifications_processed - just_sent_message = 'Your {} been sent. Printing starts {} at 5:30pm.'.format( 'letter has' if job.notification_count == 1 else 'letters have', printing_today_or_tomorrow() @@ -87,7 +84,6 @@ def view_job(service_id, job_id): return render_template( 'views/jobs/job.html', - finished=(total_notifications == processed_notifications), job=job, status=request.args.get('status', ''), updates_url=url_for( diff --git a/app/models/job.py b/app/models/job.py index e81e31890..1515eda46 100644 --- a/app/models/job.py +++ b/app/models/job.py @@ -83,10 +83,13 @@ class Job(JSONModel): @property def still_processing(self): return ( - self.status != 'finished' or - self.notifications_created < self.notification_count + self.status != 'finished' or self.percentage_complete < 100 ) + @cached_property + def finished_processing(self): + return self.notification_count == self.notifications_processed + @property def template_id(self): return self._dict['template'] diff --git a/app/templates/partials/jobs/notifications.html b/app/templates/partials/jobs/notifications.html index 779bc4360..16b6c449a 100644 --- a/app/templates/partials/jobs/notifications.html +++ b/app/templates/partials/jobs/notifications.html @@ -28,7 +28,7 @@ {% if template.template_type == 'letter' %}
{% endif %} - {% if job.percentage_complete < 100 and job.job_status != 'finished' %} + {% if job.still_processing %}

Report is {{ "{:.0f}%".format(job.percentage_complete * 0.99) }} complete…

diff --git a/app/templates/views/jobs/job.html b/app/templates/views/jobs/job.html index c2906612d..79080d928 100644 --- a/app/templates/views/jobs/job.html +++ b/app/templates/views/jobs/job.html @@ -16,10 +16,10 @@ {% if just_sent %} {{ banner(just_sent_message, type='default', with_tick=True) }} {% else %} - {{ ajax_block(partials, updates_url, 'status', finished=finished) }} + {{ ajax_block(partials, updates_url, 'status', finished=job.processing_finished) }} {% endif %} - {{ ajax_block(partials, updates_url, 'counts', finished=finished) }} - {{ ajax_block(partials, updates_url, 'notifications', finished=finished) }} + {{ ajax_block(partials, updates_url, 'counts', finished=job.processing_finished) }} + {{ ajax_block(partials, updates_url, 'notifications', finished=job.processing_finished) }} {% if job.letter_job_can_be_cancelled %}