diff --git a/app/response/utils.py b/app/response/utils.py index 7bbf611e5..f2787aac7 100644 --- a/app/response/utils.py +++ b/app/response/utils.py @@ -708,8 +708,27 @@ def _closing_email_handler(request_id, data, page, agency_name, email_template): if content.endswith(TINYMCE_EDITABLE_P_TAG): content = content[:-len(TINYMCE_EDITABLE_P_TAG)] else: - reasons = [Reasons.query.filter_by(id=reason_id).one().content - for reason_id in data.getlist('reason_ids[]')] + _reasons = [Reasons.query.with_entities(Reasons.title, Reasons.content).filter_by(id=reason_id).one() + for reason_id in data.getlist('reason_ids[]')] + + # Determine if a custom reason is used + # TODO: Hardcoded values; Need to figure out a better way to do this; Might be part of Agency Features at a later date. + custom_reasons = any('Denied - Reason Below' in x[0] for x in _reasons) + + # In order to handle the custom logic for an empty denial reason, remove the reason from the list and pass in + # "custom_reasons" to the template so that the code is generated correctly. + if custom_reasons: + for reason in _reasons: + if reason[0] == 'Denied - Reason Below': + _reasons.remove(reason) + break + + reasons = render_template( + os.path.join(current_app.config['EMAIL_TEMPLATE_DIR'], '_email_response_determinations_list.html'), + reasons=_reasons, + custom_reasons=custom_reasons + ) + default_content = True content = None header = None diff --git a/app/templates/email_templates/_email_response_determinations_list.html b/app/templates/email_templates/_email_response_determinations_list.html index 2dac7c261..4c8880812 100644 --- a/app/templates/email_templates/_email_response_determinations_list.html +++ b/app/templates/email_templates/_email_response_determinations_list.html @@ -6,5 +6,5 @@ {% if custom_reasons %} -

+



{% endif %} \ No newline at end of file diff --git a/app/templates/email_templates/email_response_closing.html b/app/templates/email_templates/email_response_closing.html index 360013773..9c220fd98 100644 --- a/app/templates/email_templates/email_response_closing.html +++ b/app/templates/email_templates/email_response_closing.html @@ -3,9 +3,7 @@ The {{ agency_name }} has closed your FOIL request {{ request.id }} for the following reason{% if reasons|length > 1 %}s{% endif %}: - {% for reason in reasons %} -

   {{ reason }}

- {% endfor %} + {{ reasons | safe }} You may appeal the decision to deny access to material that was redacted in part or withheld in entirety by contacting the agency's FOIL Appeals Officer: