Add asset versioning for cache-busting in templates and configuration

This commit is contained in:
2026-04-10 16:10:30 +02:00
parent 1931e07013
commit 9212ad04f5
3 changed files with 23 additions and 2 deletions
Binary file not shown.
+21
View File
@@ -92,6 +92,25 @@ SCHOOL_PERIODS = cfg.SCHOOL_PERIODS
# Apply the configuration for general use throughout the app
APP_VERSION = __version__
RELEASE_STATE_FILE = os.path.join(os.path.dirname(BASE_DIR), '.release-version')
def _get_asset_version():
"""Return a cache-busting asset version tied to deployment state."""
env_version = os.getenv('INVENTAR_ASSET_VERSION', '').strip()
if env_version:
return env_version
try:
if os.path.exists(RELEASE_STATE_FILE):
with open(RELEASE_STATE_FILE, 'r', encoding='utf-8') as f:
release_tag = f.read().strip()
if release_tag:
return release_tag
except Exception:
pass
return APP_VERSION
def _parse_money_value(value):
@@ -293,6 +312,7 @@ def _prepare_invoice_pdf_payload(invoice_data, borrow_doc=None, item_doc=None):
def inject_version():
"""Inject global template variables."""
is_admin = False
asset_version = _get_asset_version()
if 'username' in session:
try:
is_admin = us.check_admin(session['username'])
@@ -300,6 +320,7 @@ def inject_version():
is_admin = False
return {
'APP_VERSION': APP_VERSION,
'ASSET_VERSION': asset_version,
'school_periods': SCHOOL_PERIODS,
'library_module_enabled': cfg.LIBRARY_MODULE_ENABLED,
'student_cards_module_enabled': cfg.STUDENT_CARDS_MODULE_ENABLED,
+2 -2
View File
@@ -20,8 +20,8 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css', v=APP_VERSION) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/planned_appointments.css', v=APP_VERSION) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css', v=ASSET_VERSION) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/planned_appointments.css', v=ASSET_VERSION) }}">
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<style>