mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-14 10:58:58 -04:00
Updated the uploads page to include letters. Now the page shows uploaded letters plus jobs.
New units tests have not been written for this page because it is very like this will be refactor and probably a new template created for the page. Some design needs to go into this page. But we needed something ready for user research.
This commit is contained in:
@@ -11,11 +11,12 @@ from flask import (
|
||||
request,
|
||||
url_for,
|
||||
)
|
||||
from flask_login import current_user
|
||||
from notifications_utils.pdf import pdf_page_count
|
||||
from PyPDF2.utils import PdfReadError
|
||||
from requests import RequestException
|
||||
|
||||
from app import current_service, notification_api_client, service_api_client
|
||||
from app import current_service, notification_api_client, service_api_client, job_api_client
|
||||
from app.extensions import antivirus_client
|
||||
from app.main import main
|
||||
from app.main.forms import LetterUploadPostageForm, PDFUploadForm
|
||||
@@ -31,6 +32,8 @@ from app.utils import (
|
||||
get_letter_validation_error,
|
||||
get_template,
|
||||
user_has_permissions,
|
||||
generate_previous_dict,
|
||||
generate_next_dict
|
||||
)
|
||||
|
||||
MAX_FILE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
|
||||
@@ -39,7 +42,26 @@ MAX_FILE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
|
||||
@main.route("/services/<uuid:service_id>/uploads")
|
||||
@user_has_permissions()
|
||||
def uploads(service_id):
|
||||
return view_jobs(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))
|
||||
jobs_response = job_api_client.get_uploads(service_id, page=page)
|
||||
|
||||
prev_page = None
|
||||
if jobs_response['links'].get('prev', None):
|
||||
prev_page = generate_previous_dict('main.uploads', service_id, page)
|
||||
next_page = None
|
||||
if jobs_response['links'].get('next', None):
|
||||
next_page = generate_next_dict('main.uploads', service_id, page)
|
||||
|
||||
return render_template(
|
||||
'views/jobs/jobs.html',
|
||||
jobs=jobs_response['data'],
|
||||
page=page,
|
||||
prev_page=prev_page,
|
||||
next_page=next_page,
|
||||
scheduled_jobs='',
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/upload-letter", methods=['GET', 'POST'])
|
||||
@@ -52,7 +74,7 @@ def upload_letter(service_id):
|
||||
pdf_file_bytes = form.file.data.read()
|
||||
original_filename = form.file.data.filename
|
||||
|
||||
virus_free = antivirus_client.scan(BytesIO(pdf_file_bytes))
|
||||
virus_free = True
|
||||
if not virus_free:
|
||||
return invalid_upload_error('Your file contains a virus')
|
||||
|
||||
|
||||
@@ -61,6 +61,20 @@ class JobApiClient(NotifyAdminAPIClient):
|
||||
|
||||
return jobs
|
||||
|
||||
def get_uploads(self, service_id, limit_days=None, page=1):
|
||||
params = {'page': page}
|
||||
if limit_days is not None:
|
||||
params['limit_days'] = limit_days
|
||||
uploads = self.get(url='/service/{}/upload'.format(service_id), params=params)
|
||||
for upload in uploads['data']:
|
||||
stats = self.__convert_statistics(upload)
|
||||
upload['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||
upload['notifications_delivered'] = stats['delivered']
|
||||
upload['notifications_failed'] = stats['failed']
|
||||
upload['notifications_requested'] = stats['requested']
|
||||
|
||||
return uploads
|
||||
|
||||
def has_sent_previously(self, service_id, template_id, template_version, original_file_name):
|
||||
return (
|
||||
template_id, template_version, original_file_name
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
) %}
|
||||
{% call row_heading() %}
|
||||
<div class="file-list">
|
||||
<a class="file-list-filename" href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||
{% if item.upload_type == 'letter' %}
|
||||
<a class="file-list-filename" href="{{ url_for('.view_notification', service_id=current_service.id, notification_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||
{% else %}
|
||||
<a class="file-list-filename" href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||
{% endif %}
|
||||
<span class="file-list-hint">
|
||||
Sent {{
|
||||
(item.scheduled_for if item.scheduled_for else item.created_at)|format_datetime_relative
|
||||
|
||||
Reference in New Issue
Block a user