mirror of
https://github.com/dnlbauer/django-signposting.git
synced 2026-09-11 06:25:30 +00:00
make linter happy
This commit is contained in:
@@ -41,6 +41,7 @@ class SignpostingMiddleware:
|
||||
|
||||
response["Link"] = " , ".join(link_snippets)
|
||||
|
||||
|
||||
class HtmlSignpostingMiddleware(SignpostingMiddleware):
|
||||
def __init__(self, get_response: Callable[[HttpRequest], HttpResponse]):
|
||||
self.get_response = get_response
|
||||
@@ -50,15 +51,15 @@ class HtmlSignpostingMiddleware(SignpostingMiddleware):
|
||||
|
||||
if not hasattr(response, "_signposts"):
|
||||
return response
|
||||
|
||||
|
||||
# Adding Signposts via HTML is only supported for HTML responses
|
||||
if not response.headers["Content-Type"].startswith("text/html"):
|
||||
return response
|
||||
|
||||
|
||||
content = response.content.decode("utf-8")
|
||||
soup = BeautifulSoup(content, "html.parser")
|
||||
|
||||
# Html should have a root element
|
||||
# Html should have a root element
|
||||
if not soup.html:
|
||||
raise Exception("Could not find HTML root element")
|
||||
|
||||
@@ -67,7 +68,6 @@ class HtmlSignpostingMiddleware(SignpostingMiddleware):
|
||||
head_tag = soup.new_tag("head")
|
||||
soup.html.insert(0, head_tag)
|
||||
|
||||
|
||||
# BUild links for each signpost and add them to the html
|
||||
for signpost in response._signposts:
|
||||
link_tag = soup.new_tag("link")
|
||||
@@ -79,13 +79,12 @@ class HtmlSignpostingMiddleware(SignpostingMiddleware):
|
||||
|
||||
# Override the original content with the new HTML
|
||||
response.content = soup.prettify().encode("utf-8")
|
||||
response['Content-Length'] = len(response.content)
|
||||
|
||||
response["Content-Length"] = len(response.content)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
class JsonLdSignpostingParserMiddleware(MiddlewareMixin):
|
||||
|
||||
def process_response(
|
||||
self, request: HttpRequest, response: HttpResponse
|
||||
) -> HttpResponse:
|
||||
|
||||
Reference in New Issue
Block a user