Refactor out function to get page count

This has been moved to the letters utils file since it will be used in
more than one place. The notification parameter has been removed so that
the function can be used when we don't have a notification id.
This commit is contained in:
Katie Smith
2019-09-05 16:45:48 +01:00
parent a241fe4a29
commit 081543a2a9
3 changed files with 22 additions and 30 deletions

View File

@@ -1,3 +1,5 @@
import io
import math
from datetime import datetime, timedelta
from enum import Enum
@@ -5,6 +7,7 @@ import boto3
from flask import current_app
from notifications_utils.letter_timings import LETTER_PROCESSING_DEADLINE
from notifications_utils.pdf import pdf_page_count
from notifications_utils.s3 import s3upload
from notifications_utils.timezones import convert_utc_to_bst
@@ -201,3 +204,10 @@ def letter_print_day(created_at):
else:
print_date = bst_print_datetime.strftime('%d %B').lstrip('0')
return 'on {}'.format(print_date)
def get_page_count(pdf):
pages = pdf_page_count(io.BytesIO(pdf))
pages_per_sheet = 2
billable_units = math.ceil(pages / pages_per_sheet)
return billable_units