notify-api-412 use black to enforce python style standards

This commit is contained in:
Kenneth Kehl
2023-08-23 10:35:43 -07:00
parent a7898118d7
commit 026dc14021
586 changed files with 33990 additions and 23461 deletions

View File

@@ -4,5 +4,5 @@ get_inbound_sms_for_service_schema = {
"type": "object",
"properties": {
"phone_number": {"type": "string"},
}
},
}

View File

@@ -16,48 +16,57 @@ from app.inbound_sms.inbound_sms_schemas import (
from app.schema_validation import validate
inbound_sms = Blueprint(
'inbound_sms',
__name__,
url_prefix='/service/<uuid:service_id>/inbound-sms'
"inbound_sms", __name__, url_prefix="/service/<uuid:service_id>/inbound-sms"
)
register_errors(inbound_sms)
@inbound_sms.route('', methods=['POST'])
@inbound_sms.route("", methods=["POST"])
def post_inbound_sms_for_service(service_id):
form = validate(request.get_json(), get_inbound_sms_for_service_schema)
user_number = form.get('phone_number')
user_number = form.get("phone_number")
# TODO update this for US formatting
# if user_number:
# # we use this to normalise to an international phone number - but this may fail if it's an alphanumeric
# user_number = try_validate_and_format_phone_number(user_number, international=True)
inbound_data_retention = fetch_service_data_retention_by_notification_type(service_id, 'sms')
limit_days = inbound_data_retention.days_of_retention if inbound_data_retention else 7
inbound_data_retention = fetch_service_data_retention_by_notification_type(
service_id, "sms"
)
limit_days = (
inbound_data_retention.days_of_retention if inbound_data_retention else 7
)
results = dao_get_inbound_sms_for_service(service_id, user_number=user_number, limit_days=limit_days)
results = dao_get_inbound_sms_for_service(
service_id, user_number=user_number, limit_days=limit_days
)
return jsonify(data=[row.serialize() for row in results])
@inbound_sms.route('/most-recent', methods=['GET'])
@inbound_sms.route("/most-recent", methods=["GET"])
def get_most_recent_inbound_sms_for_service(service_id):
# used on the service inbox page
page = request.args.get('page', 1)
page = request.args.get("page", 1)
inbound_data_retention = fetch_service_data_retention_by_notification_type(service_id, 'sms')
limit_days = inbound_data_retention.days_of_retention if inbound_data_retention else 7
inbound_data_retention = fetch_service_data_retention_by_notification_type(
service_id, "sms"
)
limit_days = (
inbound_data_retention.days_of_retention if inbound_data_retention else 7
)
# get most recent message for each user for service
results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(service_id, int(page), limit_days)
results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(
service_id, int(page), limit_days
)
return jsonify(
data=[row.serialize() for row in results.items],
has_next=results.has_next
data=[row.serialize() for row in results.items], has_next=results.has_next
)
@inbound_sms.route('/summary')
@inbound_sms.route("/summary")
def get_inbound_sms_summary_for_service(service_id):
# this is for the dashboard, so always limit to 7 days, even if they have a longer data retention
count = dao_count_inbound_sms_for_service(service_id, limit_days=7)
@@ -65,11 +74,11 @@ def get_inbound_sms_summary_for_service(service_id):
return jsonify(
count=count,
most_recent=most_recent[0].created_at.isoformat() if most_recent else None
most_recent=most_recent[0].created_at.isoformat() if most_recent else None,
)
@inbound_sms.route('/<uuid:inbound_sms_id>', methods=['GET'])
@inbound_sms.route("/<uuid:inbound_sms_id>", methods=["GET"])
def get_inbound_by_id(service_id, inbound_sms_id):
message = dao_get_inbound_sms_by_id(service_id, inbound_sms_id)