Enable debug mode in config, enhance HTML response handling with minification, and clean up worklog template by removing commented button
This commit is contained in:
parent
fa37497e3a
commit
f17051224d
5 changed files with 35 additions and 29 deletions
|
@ -9,7 +9,7 @@ def quote(value: str) -> str:
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
TESTING = False
|
TESTING = False
|
||||||
|
|
||||||
DB_BACKEND = os.getenv('DB_BACKEND', 'sqlite').lower()
|
DB_BACKEND = os.getenv('DB_BACKEND', 'sqlite').lower()
|
||||||
|
|
|
@ -1,18 +1,30 @@
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
|
import re
|
||||||
|
|
||||||
from . import main
|
from . import main
|
||||||
|
|
||||||
@main.after_request
|
@main.after_request
|
||||||
def prettify_html_response(response):
|
def prettify_or_minify_html_response(response):
|
||||||
if app.debug and response.content_type.startswith("text/html"):
|
print(app.debug, response.content_type)
|
||||||
|
if response.content_type.startswith("text/html"):
|
||||||
try:
|
try:
|
||||||
soup = BeautifulSoup(response.get_data(as_text=True), 'html5lib')
|
html = response.get_data(as_text=True)
|
||||||
pretty_html = soup.prettify()
|
soup = BeautifulSoup(html, 'html5lib')
|
||||||
|
|
||||||
|
if app.debug:
|
||||||
|
pretty_html = soup.prettify()
|
||||||
|
response.set_data(pretty_html.encode("utf-8")) # type: ignore
|
||||||
|
else:
|
||||||
|
# Minify by stripping extra whitespace between tags and inside text
|
||||||
|
minified_html = re.sub(r">\s+<", "><", str(soup)) # collapse whitespace between tags
|
||||||
|
minified_html = re.sub(r"\s{2,}", " ", minified_html) # collapse multi-spaces to one
|
||||||
|
minified_html = re.sub(r"\n+", "", minified_html) # remove newlines
|
||||||
|
|
||||||
|
response.set_data(minified_html.encode("utf-8")) # type: ignore
|
||||||
|
|
||||||
response.set_data(pretty_html.encode("utf-8")) # type: ignore
|
|
||||||
response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Prettifying failed: {e}")
|
print(f"⚠️ Prettifying/Minifying failed: {e}")
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -263,37 +263,35 @@
|
||||||
) }}
|
) }}
|
||||||
</div>
|
</div>
|
||||||
{% if worklog %}
|
{% if worklog %}
|
||||||
<div class="col" id="worklog" style="max-height: 300px">
|
<div class="col" id="worklog">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col form-label">
|
<div class="col form-label">
|
||||||
Work Log Entries
|
Work Log Entries
|
||||||
{% set id_list = worklog_rows | map(attribute='id') | list %}
|
{% set id_list = worklog_rows | map(attribute='id') | list %}
|
||||||
{{ links.export_link(
|
{{ links.export_link(
|
||||||
id = (item.identifier | replace('Name: ', '')
|
id = (item.identifier | replace('Name: ', '')
|
||||||
| replace('ID:', '')
|
| replace('ID:', '')
|
||||||
| replace('Serial: ', '')
|
| replace('Serial: ', '')
|
||||||
| replace('Barcode: ', '')
|
| replace('Barcode: ', '')
|
||||||
| lower) + '_worklog',
|
| lower) + '_worklog',
|
||||||
endpoint = 'worklog',
|
endpoint = 'worklog',
|
||||||
ids = {'ids': id_list}
|
ids = {'ids': id_list}
|
||||||
) }}
|
) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row border overflow-auto">
|
<div class="row border">
|
||||||
<div class="col">
|
<div class="col overflow-auto" style="max-height: 300px;">
|
||||||
{% for note in notes %}
|
{% for note in notes %}
|
||||||
{% set title %}
|
{% set title %}
|
||||||
{{ note.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{{ links.entry_link('worklog_entry', note.work_log_id) }}
|
{{ note.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{{ links.entry_link('worklog_entry', note.work_log_id) }}
|
||||||
{% endset %}
|
{% endset %}
|
||||||
<div class="row">
|
{{ editor.render_editor(
|
||||||
{{ editor.render_editor(
|
id = 'updates' + (note.id | string),
|
||||||
id = 'updates' + (note.id | string),
|
title = title,
|
||||||
title = title,
|
content = note.content,
|
||||||
content = note.content,
|
mode = 'view',
|
||||||
mode = 'view',
|
enabled = false
|
||||||
enabled = false
|
) }}
|
||||||
) }}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -219,11 +219,6 @@
|
||||||
<label class="form-label">Updates</label>
|
<label class="form-label">Updates</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{#
|
|
||||||
<button class="btn btn-primary mb-3" id="addUpdateButton"{% if log.complete %} disabled{% endif %}>
|
|
||||||
{{ icons.render_icon('plus-lg', 16) }}
|
|
||||||
</button>
|
|
||||||
#}
|
|
||||||
{% set addUpdateLogic %}
|
{% set addUpdateLogic %}
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
const pad = (n) => String(n).padStart(2, '0');
|
const pad = (n) => String(n).padStart(2, '0');
|
||||||
|
|
|
@ -11,6 +11,7 @@ dependencies = [
|
||||||
"pandas",
|
"pandas",
|
||||||
"pyodbc",
|
"pyodbc",
|
||||||
"python-dotenv",
|
"python-dotenv",
|
||||||
|
"waitress",
|
||||||
"Werkzeug"
|
"Werkzeug"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue