Skip to content

Commit

Permalink
Run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
quis committed Feb 21, 2025
1 parent ee5ed0e commit ffc4c0f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
)
73 changes: 49 additions & 24 deletions app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -1481,7 +1497,9 @@ def email_template_manage_attachment_retention(template_id, service_id):
)


@main.route("/services/<uuid:service_id>/templates/<uuid:template_id>/attachment/email-confirmation", methods=["GET", "POST"])
@main.route(
"/services/<uuid:service_id>/templates/<uuid:template_id>/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)
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions app/models/template_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
}
11 changes: 7 additions & 4 deletions app/utils/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ffc4c0f

Please sign in to comment.