Move letter length check to utils repo so template-preview can use it, too

Update requirements
This commit is contained in:
Pea Tyczynska
2019-10-09 14:56:18 +01:00
parent c524b0bbf5
commit 2ed1e382b4
8 changed files with 20 additions and 85 deletions

View File

@@ -15,8 +15,9 @@ from flask import (
)
from flask_login import current_user
from notifications_python_client.errors import HTTPError
from notifications_utils import SMS_CHAR_COUNT_LIMIT
from notifications_utils import LETTER_MAX_PAGE_COUNT, SMS_CHAR_COUNT_LIMIT
from notifications_utils.columns import Columns
from notifications_utils.pdf import is_letter_too_long
from notifications_utils.recipients import (
RecipientCSV,
first_column_headings,
@@ -48,14 +49,12 @@ from app.s3_client.s3_csv_client import (
)
from app.template_previews import TemplatePreview, get_page_count_for_letter
from app.utils import (
LETTER_MAX_PAGES,
PermanentRedirect,
Spreadsheet,
email_or_sms_not_enabled,
get_errors_for_csv,
get_help_argument,
get_template,
is_letter_too_long,
should_skip_template_page,
unicode_truncate,
user_has_permissions,
@@ -596,7 +595,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
service_id, template.id, db_template['version'], request.args.get('original_file_name', '')
),
letter_too_long=is_letter_too_long(page_count),
letter_max_pages=LETTER_MAX_PAGES,
letter_max_pages=LETTER_MAX_PAGE_COUNT,
)
@@ -890,7 +889,7 @@ def _check_notification(service_id, template_id, exception=None):
back_link=back_link,
help=get_help_argument(),
letter_too_long=is_letter_too_long(page_count),
letter_max_pages=LETTER_MAX_PAGES,
letter_max_pages=LETTER_MAX_PAGE_COUNT,
**(get_template_error_dict(exception) if exception else {}),
)

View File

@@ -6,7 +6,9 @@ from flask import abort, flash, redirect, render_template, request, url_for
from flask_login import current_user
from markupsafe import Markup
from notifications_python_client.errors import HTTPError
from notifications_utils import LETTER_MAX_PAGE_COUNT
from notifications_utils.formatters import nl2br
from notifications_utils.pdf import is_letter_too_long
from notifications_utils.recipients import first_column_headings
from app import (
@@ -31,10 +33,8 @@ from app.models.service import Service
from app.models.template_list import TemplateList, TemplateLists
from app.template_previews import TemplatePreview, get_page_count_for_letter
from app.utils import (
LETTER_MAX_PAGES,
email_or_sms_not_enabled,
get_template,
is_letter_too_long,
should_skip_template_page,
user_has_permissions,
user_is_platform_admin,
@@ -77,7 +77,7 @@ def view_template(service_id, template_id):
template_postage=template["postage"],
user_has_template_permission=user_has_template_permission,
letter_too_long=is_letter_too_long(get_page_count_for_letter(template)),
letter_max_pages=LETTER_MAX_PAGES,
letter_max_pages=LETTER_MAX_PAGE_COUNT,
)

View File

@@ -26,12 +26,7 @@ from app.s3_client.s3_letter_upload_client import (
upload_letter_to_s3,
)
from app.template_previews import TemplatePreview, sanitise_letter
from app.utils import (
LETTER_MAX_PAGES,
get_template,
is_letter_too_long,
user_has_permissions,
)
from app.utils import get_template, user_has_permissions
MAX_FILE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
@@ -83,10 +78,7 @@ def upload_letter(service_id):
else:
raise ex
else:
if is_letter_too_long(page_count):
status = 'invalid'
else:
status = 'valid'
status = 'valid'
file_contents = base64.b64decode(response.json()['file'].encode())
upload_letter_to_s3(
file_contents,
@@ -117,7 +109,6 @@ def uploaded_letter_preview(service_id, file_id):
metadata = get_letter_metadata(service_id, file_id)
original_filename = metadata.get('filename')
page_count = metadata.get('page_count')
letter_too_long = is_letter_too_long(int(page_count))
status = metadata.get('status')
template_dict = service_api_client.get_precompiled_template(service_id)
@@ -139,8 +130,6 @@ def uploaded_letter_preview(service_id, file_id):
template=template,
status=status,
file_id=file_id,
letter_too_long=letter_too_long,
letter_max_pages=LETTER_MAX_PAGES,
)