fix flake8

This commit is contained in:
Kenneth Kehl
2024-07-25 12:38:33 -07:00
13 changed files with 67 additions and 56 deletions

View File

@@ -1,5 +1,4 @@
import calendar
from collections import defaultdict
from datetime import datetime
from functools import partial
from itertools import groupby
@@ -13,7 +12,6 @@ from app import (
billing_api_client,
current_service,
job_api_client,
notification_api_client,
service_api_client,
socketio,
template_statistics_client,
@@ -83,18 +81,9 @@ def service_dashboard(service_id):
return redirect(url_for("main.choose_template", service_id=service_id))
job_response = job_api_client.get_jobs(service_id)["data"]
notifications_response = notification_api_client.get_notifications_for_service(
service_id
)["notifications"]
service_data_retention_days = 7
aggregate_notifications_by_job = defaultdict(list)
for notification in notifications_response:
job_id = notification.get("job", {}).get("id", None)
if job_id:
aggregate_notifications_by_job[job_id].append(notification)
job_and_notifications = [
jobs = [
{
"job_id": job["id"],
"time_left": get_time_left(job["created_at"]),
@@ -105,20 +94,20 @@ def service_dashboard(service_id):
".view_job", service_id=current_service.id, job_id=job["id"]
),
"created_at": job["created_at"],
"processing_finished": job["processing_finished"],
"processing_started": job["processing_started"],
"processing_finished": job.get("processing_finished"),
"processing_started": job.get("processing_started"),
"notification_count": job["notification_count"],
"created_by": job["created_by"],
"notifications": aggregate_notifications_by_job.get(job["id"], []),
"template_name": job["template_name"],
"original_file_name": job["original_file_name"],
}
for job in job_response
if aggregate_notifications_by_job.get(job["id"], [])
]
return render_template(
"views/dashboard/dashboard.html",
updates_url=url_for(".service_dashboard_updates", service_id=service_id),
partials=get_dashboard_partials(service_id),
job_and_notifications=job_and_notifications,
jobs=jobs,
service_data_retention_days=service_data_retention_days,
)

View File

@@ -36,7 +36,11 @@ def _reformat_keystring(orig):
new_keystring = new_keystring.strip()
new_keystring = new_keystring.replace(" ", "\n")
new_keystring = "\n".join(
[f"-----BEGIN {private_key}-----", new_keystring, f"-----END {private_key}-----"]
[
f"-----BEGIN {private_key}-----",
new_keystring,
f"-----END {private_key}-----",
]
)
new_keystring = f"{new_keystring}\n"
return new_keystring
@@ -67,7 +71,9 @@ def _get_access_token(code, state):
response = requests.post(url, headers=headers)
if response.json().get("access_token") is None:
# Capture the response json here so it hopefully shows up in error reports
current_app.logger.error(f"Error when getting access token {response.json()} #notify-admin-1505")
current_app.logger.error(
f"Error when getting access token {response.json()} #notify-admin-1505"
)
raise KeyError(f"'access_token' {response.json()}")
access_token = response.json()["access_token"]
return access_token
@@ -92,7 +98,9 @@ def _do_login_dot_gov():
login_gov_error = request.args.get("error")
if login_gov_error:
current_app.logger.error(f"login.gov error: {login_gov_error} #notify-admin-1505")
current_app.logger.error(
f"login.gov error: {login_gov_error} #notify-admin-1505"
)
raise Exception(f"Could not login with login.gov {login_gov_error}")
elif code and state:
@@ -108,7 +116,9 @@ def _do_login_dot_gov():
abort(403)
redirect_url = request.args.get("next")
user = user_api_client.get_user_by_uuid_or_email(user_uuid, user_email)
current_app.logger.info(f"Retrieved user {user['id']} from db #notify-admin-1505")
current_app.logger.info(
f"Retrieved user {user['id']} from db #notify-admin-1505"
)
# Check if the email needs to be revalidated
is_fresh_email = is_less_than_days_ago(

View File

@@ -38,7 +38,7 @@ def verify_email(token):
current_app.config["EMAIL_EXPIRY_SECONDS"],
)
except SignatureExpired:
current_app.logger.error(f"Email link expired #notify-admin-1505")
current_app.logger.error("Email link expired #notify-admin-1505")
flash(
"The link in the email we sent you has expired. We've sent you a new one."
)
@@ -52,7 +52,8 @@ def verify_email(token):
if user.is_active:
current_app.logger.error(
f"User is using an invite link but is already logged in {user.id} #notify-admin-1505")
f"User is using an invite link but is already logged in {user.id} #notify-admin-1505"
)
flash("That verification link has expired.")
return redirect(url_for("main.sign_in"))