Remove deprecated routes file and move HTML prettifying logic to hooks module
This commit is contained in:
parent
4d8d5b4e6a
commit
f4369348c5
2 changed files with 2 additions and 10 deletions
|
@ -2,4 +2,4 @@ from flask import Blueprint
|
|||
|
||||
main = Blueprint('main', __name__)
|
||||
|
||||
from . import inventory, user, worklog, settings, index, search
|
||||
from . import inventory, user, worklog, settings, index, search, hooks
|
18
routes/hooks.py
Normal file
18
routes/hooks.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from bs4 import BeautifulSoup
|
||||
from flask import current_app as app
|
||||
|
||||
from . import main
|
||||
|
||||
@main.after_request
|
||||
def prettify_html_response(response):
|
||||
if app.debug and response.content_type.startswith("text/html"):
|
||||
try:
|
||||
soup = BeautifulSoup(response.get_data(as_text=True), 'html5lib')
|
||||
pretty_html = soup.prettify()
|
||||
|
||||
response.set_data(pretty_html.encode("utf-8")) # type: ignore
|
||||
response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
||||
|
||||
except Exception as e:
|
||||
print(f"⚠️ Prettifying failed: {e}")
|
||||
return response
|
Loading…
Add table
Add a link
Reference in a new issue