Enhance app configuration and prettify HTML responses; update requirements and fix button identifiers in settings template
This commit is contained in:
parent
7c15754cab
commit
4c36621eba
4 changed files with 28 additions and 8 deletions
|
@ -17,6 +17,8 @@ def create_app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = os.getenv('SECRET_KEY', 'dev-secret-key-unsafe') # You know what to do for prod
|
app.secret_key = os.getenv('SECRET_KEY', 'dev-secret-key-unsafe') # You know what to do for prod
|
||||||
app.config.from_object(Config)
|
app.config.from_object(Config)
|
||||||
|
app.jinja_env.trim_blocks = True
|
||||||
|
app.jinja_env.lstrip_blocks = True
|
||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,5 @@ dotenv
|
||||||
flask
|
flask
|
||||||
flask_sqlalchemy
|
flask_sqlalchemy
|
||||||
pandas
|
pandas
|
||||||
pyodbc
|
pyodbc
|
||||||
|
beautifulsoup4
|
17
routes.py
17
routes.py
|
@ -9,6 +9,7 @@ import pandas as pd
|
||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
main = Blueprint('main', __name__)
|
main = Blueprint('main', __name__)
|
||||||
|
|
||||||
|
@ -78,6 +79,22 @@ worklog_form_fields = {
|
||||||
"notes": lambda log: {"label": "Notes", "type": "textarea", "value": log.notes or "", "rows": 15}
|
"notes": lambda log: {"label": "Notes", "type": "textarea", "value": log.notes or "", "rows": 15}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@main.after_request
|
||||||
|
def prettify_html_response(response):
|
||||||
|
if app.debug and response.content_type.startswith("text/html"):
|
||||||
|
try:
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
@main.route("/")
|
@main.route("/")
|
||||||
def index():
|
def index():
|
||||||
worklog_query = eager_load_worklog_relationships(
|
worklog_query = eager_load_worklog_relationships(
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<form id="settingsForm">
|
<form id="settingsForm">
|
||||||
{{ breadcrumbs.breadcrumb_header(
|
{{ breadcrumbs.breadcrumb_header(
|
||||||
title=title,
|
title=title,
|
||||||
submit_button=True
|
save_button=True
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-danger" data-bs-dismiss="modal"
|
<button type="button" class="btn btn-danger" data-bs-dismiss="modal"
|
||||||
id="roomEditorCancelButton">Cancel</button>
|
id="roomEditorCancelButton">Cancel</button>
|
||||||
<button type="button" class="btn btn-primary" id="roomEditorSaveButton">Save</button>
|
<button type="button" class="btn btn-primary" id="editorSaveButton">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -196,9 +196,9 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const modal = document.getElementById('roomEditor');
|
const modal = document.getElementById('roomEditor');
|
||||||
const saveButton = document.getElementById('roomEditorSaveButton');
|
const saveButton = document.getElementById('saveButton')
|
||||||
|
const editorSaveButton = document.getElementById('editorSaveButton');
|
||||||
const cancelButton = document.getElementById('roomEditorCancelButton');
|
const cancelButton = document.getElementById('roomEditorCancelButton');
|
||||||
const form = document.getElementById('settingsForm');
|
const form = document.getElementById('settingsForm');
|
||||||
|
|
||||||
|
@ -234,8 +234,9 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
form.addEventListener('submit', async (event) => {
|
saveButton.addEventListener('click', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
console.log("Test")
|
||||||
const state = buildFormState();
|
const state = buildFormState();
|
||||||
|
|
||||||
if (!isSerializable(state)) {
|
if (!isSerializable(state)) {
|
||||||
|
@ -273,7 +274,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
saveButton.addEventListener('click', () => {
|
editorSaveButton.addEventListener('click', () => {
|
||||||
const name = document.getElementById('roomName').value.trim();
|
const name = document.getElementById('roomName').value.trim();
|
||||||
const sectionVal = document.getElementById('roomSection').value;
|
const sectionVal = document.getElementById('roomSection').value;
|
||||||
const funcVal = document.getElementById('roomFunction').value;
|
const funcVal = document.getElementById('roomFunction').value;
|
||||||
|
@ -309,5 +310,4 @@
|
||||||
cancelButton.addEventListener('click', () => {
|
cancelButton.addEventListener('click', () => {
|
||||||
bootstrap.Modal.getInstance(modal).hide();
|
bootstrap.Modal.getInstance(modal).hide();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue