Use a ModelList for lists of jobs

This follows the pattern of what we’ve done with services, users and
events.

It gives us a way of neatly instantiating a model for each item in the
list we get back from the API and reduces the complexity of the view
layer code.

Now is a good time to do this because we’re going to be making a bunch
of changes to the jobs pages, and those changes will be easier to code
and understand with a sensible model behind them.
This commit is contained in:
Chris Hill-Scott
2020-01-08 14:29:56 +00:00
parent 5e7ec3e30d
commit 25464a141b
13 changed files with 106 additions and 76 deletions

View File

@@ -15,12 +15,7 @@ from notifications_utils.pdf import pdf_page_count
from PyPDF2.utils import PdfReadError
from requests import RequestException
from app import (
current_service,
job_api_client,
notification_api_client,
service_api_client,
)
from app import current_service, notification_api_client, service_api_client
from app.extensions import antivirus_client
from app.main import main
from app.main.forms import LetterUploadPostageForm, PDFUploadForm
@@ -47,20 +42,18 @@ MAX_FILE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
def uploads(service_id):
# No tests have been written, this has been quickly prepared for user research.
# It's also very like that a new view will be created to show uploads.
page = int(request.args.get('page', 1))
uploads_response = job_api_client.get_uploads(service_id, page=page)
uploads = current_service.get_page_of_uploads(page=request.args.get('page'))
prev_page = None
if uploads_response['links'].get('prev', None):
prev_page = generate_previous_dict('main.uploads', service_id, page)
if uploads.next_page:
prev_page = generate_previous_dict('main.uploads', service_id, uploads.current_page)
next_page = None
if uploads_response['links'].get('next', None):
next_page = generate_next_dict('main.uploads', service_id, page)
if uploads.prev_page:
next_page = generate_next_dict('main.uploads', service_id, uploads.current_page)
return render_template(
'views/jobs/jobs.html',
jobs=uploads_response['data'],
page=page,
jobs=uploads,
prev_page=prev_page,
next_page=next_page,
scheduled_jobs='',