Skip to content

Commit

Permalink
lint python
Browse files Browse the repository at this point in the history
  • Loading branch information
immortalcodes committed Sep 19, 2024
1 parent 0c02e5c commit 9a8aa86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
16 changes: 12 additions & 4 deletions webapp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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("/<path:file_path>", view_func=get_asset)
api_blueprint.add_url_rule("/<path:file_path>", view_func=update_asset, methods=["PUT"])
api_blueprint.add_url_rule(
"/<path:file_path>", view_func=update_asset, methods=["PUT"]
)
api_blueprint.add_url_rule(
"/<path:file_path>", view_func=delete_asset, methods=["DELETE"]
)
Expand All @@ -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/<path:redirect_path>", view_func=get_redirect)
api_blueprint.add_url_rule(
"/redirects", view_func=create_redirect, methods=["POST"]
)
api_blueprint.add_url_rule(
"/redirects/<path:redirect_path>", view_func=get_redirect
)
api_blueprint.add_url_rule(
"/redirects/<path:redirect_path>",
view_func=update_redirect,
Expand Down
28 changes: 22 additions & 6 deletions webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 9a8aa86

Please sign in to comment.