Refactor to use is_precompiled_letter in letters/utils.py

This commit is contained in:
Ken Tsang
2018-03-06 13:04:57 +00:00
parent bca858f4a8
commit 28136734e4
3 changed files with 10 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ from flask import current_app
from notifications_utils.s3 import s3upload
from app.models import LETTER_TYPE
from app.variables import Retention
@@ -79,4 +80,8 @@ def get_letter_pdf(notification):
def is_precompiled_letter(template):
return template.hidden and template.name == current_app.config['PRECOMPILED_TEMPLATE_NAME']
return (
template.template_type == LETTER_TYPE and
template.hidden and
template.name == current_app.config['PRECOMPILED_TEMPLATE_NAME']
)

View File

@@ -2,7 +2,6 @@ from datetime import (
datetime,
date,
timedelta)
from flask import current_app
from flask_marshmallow.fields import fields
from marshmallow import (
post_load,
@@ -25,6 +24,7 @@ from notifications_utils.recipients import (
from app import ma
from app import models
from app.letters.utils import is_precompiled_letter
from app.models import ServicePermission
from app.dao.permissions_dao import permission_dao
from app.utils import get_template_instance
@@ -315,11 +315,7 @@ class BaseTemplateSchema(BaseSchema):
return template.get_reply_to_text()
def get_precompiled_letter(self, template):
return (
template.template_type == 'letter' and
template.hidden and
template.name == current_app.config['PRECOMPILED_TEMPLATE_NAME']
)
return is_precompiled_letter(template)
class Meta:
model = models.Template

View File

@@ -14,6 +14,7 @@ from app.dao.templates_dao import (
dao_get_template_by_id_and_service_id
)
from app.letters.utils import is_precompiled_letter
from app.schemas import notification_with_template_schema
from app.utils import cache_key_for_service_template_counter
from app.errors import register_errors, InvalidRequest
@@ -48,11 +49,7 @@ def get_template_statistics_for_service_by_day(service_id):
'template_id': str(data.template_id),
'template_name': data.name,
'template_type': data.template_type,
'precompiled_letter': (
data.template_type == 'letter' and
data.hidden and
data.name == current_app.config['PRECOMPILED_TEMPLATE_NAME']
)
'precompiled_letter': is_precompiled_letter(data)
}
return jsonify(data=[serialize(row) for row in stats])