diff --git a/app/main/forms.py b/app/main/forms.py index 22cb3d0110..29ae203783 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -2998,4 +2998,4 @@ class EmailAttachmentForm(StripWhitespaceForm): DataRequired(message="You need to chose a file to upload"), FileSize(max_size=10 * 1024 * 1024, message="The file must be smaller than 10MB"), ], - ) \ No newline at end of file + ) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 7c5cf10850..46517025aa 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -1405,27 +1405,29 @@ def email_template_manage_attachments(template_id, service_id): { "key": { "classes": "notify-summary-list__key notify-summary-list__key--35-100", - "html": Field(f"(({placeholder}))") + "html": Field(f"(({placeholder}))"), }, "value": { "text": template.attachments[placeholder].file_name or "No file attached", - "classes": "govuk-summary-list__value--truncate" if template.attachments[placeholder] else "govuk-summary-list__value--truncate govuk-hint", + "classes": "govuk-summary-list__value--truncate" + if template.attachments[placeholder] + else "govuk-summary-list__value--truncate govuk-hint", }, "actions": { - "items": [ - { - "href": url_for( - 'main.email_template_manage_attachment', - service_id=service_id, - template_id=template_id, - placeholder=placeholder.strip(), - ), - "text": "Change", - "visuallyHiddenText": "service name", - "classes": "govuk-link--no-visited-state" - } - ] - } + "items": [ + { + "href": url_for( + "main.email_template_manage_attachment", + service_id=service_id, + template_id=template_id, + placeholder=placeholder.strip(), + ), + "text": "Change", + "visuallyHiddenText": "service name", + "classes": "govuk-link--no-visited-state", + } + ] + }, } for placeholder in template.all_placeholders ] @@ -1447,10 +1449,19 @@ def email_template_manage_attachment(template_id, service_id): form = EmailAttachmentForm() if delete and request.method == "POST": del template.attachments[placeholder] - return redirect(url_for('main.email_template_manage_attachments', service_id=current_service.id, template_id=template.id)) + return redirect( + url_for("main.email_template_manage_attachments", service_id=current_service.id, template_id=template.id) + ) if form.validate_on_submit(): attachment.file_name = form.file.data.filename - return redirect(url_for('main.email_template_manage_attachment', service_id=current_service.id, template_id=template.id, placeholder=placeholder)) + return redirect( + url_for( + "main.email_template_manage_attachment", + service_id=current_service.id, + template_id=template.id, + placeholder=placeholder, + ) + ) return render_template( "views/templates/manage-email-attachment.html", template=template, @@ -1467,12 +1478,17 @@ def email_template_manage_attachment_retention(template_id, service_id): template = current_service.get_template(template_id) placeholder = request.args.get("placeholder") attachment = template.attachments[placeholder] - form = SetServiceAttachmentDataRetentionForm( - weeks_of_retention=attachment.weeks_of_retention - ) + form = SetServiceAttachmentDataRetentionForm(weeks_of_retention=attachment.weeks_of_retention) if form.validate_on_submit(): attachment.weeks_of_retention = form.weeks_of_retention.data - return redirect(url_for('main.email_template_manage_attachment', service_id=current_service.id, template_id=template.id, placeholder=placeholder)) + return redirect( + url_for( + "main.email_template_manage_attachment", + service_id=current_service.id, + template_id=template.id, + placeholder=placeholder, + ) + ) return render_template( "views/templates/manage-email-attachment-retention.html", template=template, @@ -1481,7 +1497,9 @@ def email_template_manage_attachment_retention(template_id, service_id): ) -@main.route("/services//templates//attachment/email-confirmation", methods=["GET", "POST"]) +@main.route( + "/services//templates//attachment/email-confirmation", methods=["GET", "POST"] +) @user_has_permissions("manage_templates") def email_template_manage_attachment_email_confirmation(template_id, service_id): template = current_service.get_template(template_id) @@ -1495,7 +1513,14 @@ def email_template_manage_attachment_email_confirmation(template_id, service_id) ) if form.validate_on_submit(): attachment.email_confirmation = form.enabled.data - return redirect(url_for('main.email_template_manage_attachment', service_id=current_service.id, template_id=template.id, placeholder=placeholder)) + return redirect( + url_for( + "main.email_template_manage_attachment", + service_id=current_service.id, + template_id=template.id, + placeholder=placeholder, + ) + ) return render_template( "views/templates/manage-email-attachment-email-confirmation.html", template=template, diff --git a/app/models/template_attachment.py b/app/models/template_attachment.py index fd5d1abd7d..1770132302 100644 --- a/app/models/template_attachment.py +++ b/app/models/template_attachment.py @@ -32,8 +32,7 @@ def __bool__(self): return bool(self.file_name) -class TemplateAttachments(): - +class TemplateAttachments: BASE_URL = "https://www.download.example.gov.uk/f/" def __init__(self, template): @@ -64,13 +63,14 @@ def __delitem__(self, placeholder_name): @property def count(self): return sum( - bool(self[key]) for key in self._dict - if key in InsensitiveDict.from_keys(self._template.all_placeholders) + bool(self[key]) for key in self._dict if key in InsensitiveDict.from_keys(self._template.all_placeholders) ) @property def as_personalisation(self): return { - placeholder: f"{self.BASE_URL}{base64.b64encode(attachment['file_name'].encode()).decode()}" if attachment['file_name'] else None + placeholder: f"{self.BASE_URL}{base64.b64encode(attachment['file_name'].encode()).decode()}" + if attachment["file_name"] + else None for placeholder, attachment in self._dict.items() } diff --git a/app/utils/templates.py b/app/utils/templates.py index 3d013a4ed2..8b7aad7bf1 100644 --- a/app/utils/templates.py +++ b/app/utils/templates.py @@ -301,10 +301,13 @@ def all_placeholders(self): @property def placeholders(self): - return OrderedSet(( - placeholder for placeholder in self.all_placeholders - if InsensitiveDict.make_key(placeholder) not in self.attachments.as_personalisation.keys() - )) + return OrderedSet( + ( + placeholder + for placeholder in self.all_placeholders + if InsensitiveDict.make_key(placeholder) not in self.attachments.as_personalisation.keys() + ) + ) class LetterAttachment(JSONModel):