From 9a8aa861ad7c24146cadfff3e1abc9b0ed010a82 Mon Sep 17 00:00:00 2001 From: immortalcodes <21112002mj@gmail.com> Date: Thu, 19 Sep 2024 17:47:13 +0530 Subject: [PATCH] lint python --- webapp/routes.py | 16 ++++++++++++---- webapp/views.py | 28 ++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/webapp/routes.py b/webapp/routes.py index 0a90641..b135779 100644 --- a/webapp/routes.py +++ b/webapp/routes.py @@ -49,7 +49,9 @@ def home(): asset_type = request.values.get("type") if query or tag: - assets = asset_service.find_assets(query=query, file_type=asset_type, tag=tag) + assets = asset_service.find_assets( + query=query, file_type=asset_type, tag=tag + ) else: assets = [] @@ -133,7 +135,9 @@ def update(): api_blueprint.add_url_rule("/", view_func=get_assets) api_blueprint.add_url_rule("/", view_func=create_asset, methods=["POST"]) api_blueprint.add_url_rule("/", view_func=get_asset) -api_blueprint.add_url_rule("/", view_func=update_asset, methods=["PUT"]) +api_blueprint.add_url_rule( + "/", view_func=update_asset, methods=["PUT"] +) api_blueprint.add_url_rule( "/", view_func=delete_asset, methods=["DELETE"] ) @@ -151,8 +155,12 @@ def update(): # Redirects api_blueprint.add_url_rule("/redirects", view_func=get_redirects) -api_blueprint.add_url_rule("/redirects", view_func=create_redirect, methods=["POST"]) -api_blueprint.add_url_rule("/redirects/", view_func=get_redirect) +api_blueprint.add_url_rule( + "/redirects", view_func=create_redirect, methods=["POST"] +) +api_blueprint.add_url_rule( + "/redirects/", view_func=get_redirect +) api_blueprint.add_url_rule( "/redirects/", view_func=update_redirect, diff --git a/webapp/views.py b/webapp/views.py index 18774f6..90028e2 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -58,7 +58,9 @@ def get_asset(file_path: str): if redirect_record: # Cache permanent redirect longtime. Temporary, not so much. - max_age = "max-age=31556926" if redirect_record.permanent else "max-age=60" + max_age = ( + "max-age=31556926" if redirect_record.permanent else "max-age=60" + ) target_url = redirect_record.target_url + "?" + request_url.query response = redirect(target_url) response.headers["Cache-Control"] = max_age @@ -122,7 +124,11 @@ def update_asset(file_path): @token_required def delete_asset(file_path): - asset = db_session.query(Asset).filter(Asset.file_path == file_path).one_or_none() + asset = ( + db_session.query(Asset) + .filter(Asset.file_path == file_path) + .one_or_none() + ) if not asset: abort(404) @@ -139,7 +145,11 @@ def get_asset_info(file_path): """ Data about an asset """ - asset = db_session.query(Asset).filter(Asset.file_path == file_path).one_or_none() + asset = ( + db_session.query(Asset) + .filter(Asset.file_path == file_path) + .one_or_none() + ) if not asset: abort(404) @@ -203,7 +213,9 @@ def create_asset(): def get_tokens(): tokens = db_session.query(Token).all() return ( - jsonify([{"name": token.name, "token": token.token} for token in tokens]), + jsonify( + [{"name": token.name, "token": token.token} for token in tokens] + ), 200, ) @@ -265,7 +277,9 @@ def get_redirect(redirect_path): @token_required def get_redirects(): redirect_records = db_session.query(Redirect).all() - return jsonify([redirect_record.as_json() for redirect_record in redirect_records]) + return jsonify( + [redirect_record.as_json() for redirect_record in redirect_records] + ) @token_required @@ -300,7 +314,9 @@ def create_redirect(): return ( jsonify( { - "message": ("Another redirect with that path already exists"), + "message": ( + "Another redirect with that path already exists" + ), "redirect_path": redirect_path, "code": 409, }