WIP enforce letter page limit

This commit is contained in:
Pea Tyczynska
2019-09-27 11:12:12 +01:00
parent 3f35c634cd
commit 69d86064f4
7 changed files with 21 additions and 17 deletions

View File

@@ -38,7 +38,7 @@ from app.letters.utils import (
move_scan_to_invalid_pdf_bucket,
move_error_pdf_to_scan_bucket,
get_file_names_from_error_bucket,
get_page_count,
get_billable_units_for_pdf,
)
from app.models import (
KEY_TYPE_TEST,
@@ -211,7 +211,7 @@ def process_virus_scan_passed(self, filename):
old_pdf = scan_pdf_object.get()['Body'].read()
try:
billable_units = get_page_count(old_pdf)
billable_units = get_billable_units_for_pdf(old_pdf)
except PdfReadError:
current_app.logger.exception(msg='Invalid PDF received for notification_id: {}'.format(notification.id))
_move_invalid_letter_and_update_status(notification, filename, scan_pdf_object)

View File

@@ -211,8 +211,12 @@ def letter_print_day(created_at):
return 'on {}'.format(print_date)
def get_page_count(pdf):
pages = pdf_page_count(io.BytesIO(pdf))
def get_page_count_for_pdf(pdf):
return pdf_page_count(io.BytesIO(pdf))
def get_billable_units_for_pdf(pdf):
pages = get_page_count_for_pdf(pdf)
pages_per_sheet = 2
billable_units = math.ceil(pages / pages_per_sheet)
return billable_units

View File

@@ -31,7 +31,7 @@ from app.dao.templates_dao import dao_get_template_by_id_and_service_id, get_pre
from app.dao.users_dao import get_user_by_id
from app.letters.utils import (
get_letter_pdf_filename,
get_page_count,
get_billable_units_for_pdf,
move_uploaded_pdf_to_letters_bucket,
)
from app.v2.errors import BadRequestError
@@ -152,7 +152,7 @@ def send_pdf_letter_notification(service_id, post_data):
raise e
# Getting the page count won't raise an error since admin has already checked the PDF is valid
billable_units = get_page_count(letter.read())
billable_units = get_billable_units_for_pdf(letter.read())
personalisation = {
'address_line_1': post_data['filename']

View File

@@ -12,7 +12,7 @@ from app.clients.document_download import DocumentDownloadError
from app.config import QueueNames, TaskNames
from app.dao.notifications_dao import update_notification_status_by_reference
from app.dao.templates_dao import get_precompiled_letter_template
from app.letters.utils import upload_letter_pdf
from app.letters.utils import upload_letter_pdf, get_page_count_for_pdf
from app.models import (
SMS_TYPE,
EMAIL_TYPE,