zmiany w serwowaniu staticow

This commit is contained in:
Mateusz Gruszczyński
2025-07-05 11:45:17 +02:00
parent 2ac2266215
commit d0b6d939c0
6 changed files with 61 additions and 52 deletions

18
app.py
View File

@ -1,6 +1,7 @@
import os
import secrets
import time
import mimetypes
from datetime import datetime, timedelta
from flask import Flask, render_template, redirect, url_for, request, flash, Blueprint, send_from_directory, request
from markupsafe import Markup
@ -80,6 +81,19 @@ def serve_js(filename):
response.cache_control.must_revalidate = True
response.expires = 0
response.pragma = 'no-cache'
response.headers.pop('Content-Disposition', None)
response.headers.pop('Etag', None)
return response
@static_bp.route('/static/css/<path:filename>')
def serve_css(filename):
response = send_from_directory('static/css', filename)
#response.cache_control.public = True
#response.cache_control.max_age = 3600
response.headers['Cache-Control'] = 'public, max-age=3600'
response.headers.pop('Content-Disposition', None)
response.headers.pop('Etag', None)
#response.expires = 0
return response
app.register_blueprint(static_bp)
@ -422,6 +436,10 @@ def uploaded_file(filename):
response = send_from_directory(app.config['UPLOAD_FOLDER'], filename)
response.headers['Cache-Control'] = 'public, max-age=2592000, immutable'
response.headers.pop('Pragma', None)
response.headers.pop('Content-Disposition', None)
mime, _ = mimetypes.guess_type(filename)
if mime:
response.headers['Content-Type'] = mime
return response
@app.route('/admin')

31
static/css/style.css Normal file
View File

@ -0,0 +1,31 @@
.large-checkbox {
width: 1.5em;
height: 1.5em;
}
.clickable-item {
cursor: pointer;
}
.bg-success {
background-color: #1e7e34 !important;
}
.bg-light {
background-color: #2c2f33 !important;
}
input[type="file"]::file-selector-button {
background-color: #127429;
color: #fff;
border: none;
padding: 0.5em 1em;
border-radius: 4px;
font-weight: bold;
cursor: pointer;
transition: background 0.2s;
}
.bg-success {
background-color: #1e7e34 !important;
}
.bg-light {
background-color: #2c2f33 !important;
}

View File

@ -9,7 +9,7 @@
<form method="post">
<div class="mb-4">
<label for="title" class="form-label">Ustaw tytuł</label>
<label for="title" class="form-label">Ustaw nazwę</label>
<input type="text" class="form-control" id="title" name="title" value="{{ list.title }}" required>
</div>

View File

@ -4,16 +4,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Live Lista Zakupów{% endblock %}</title>
<link rel="icon" type="image/svg+xml" href="{{ url_for('favicon') }}">
<link href="{{ url_for('static_bp.serve_css', filename='style.css') }}" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.4/css/lightbox.min.css" rel="stylesheet">
<link rel="icon" type="image/svg+xml" href="{{ url_for('favicon') }}">
<script src="https://cdn.socket.io/4.6.1/socket.io.min.js"></script>
<script src="{{ url_for('static_bp.serve_js', filename='live.js') }}"></script>
<script src="{{ url_for('static_bp.serve_js', filename='toasts.js') }}"></script>
<script src="{{ url_for('static_bp.serve_js', filename='hide_list.js') }}"></script>
</head>
<body class="bg-dark text-white">
@ -45,12 +41,12 @@
</div>
</nav>
<div id="toast-container" class="toast-container position-fixed bottom-0 end-0 p-3"></div>
<div class="container px-2">
{% block content %}{% endblock %}
</div>
<div id="toast-container" class="toast-container position-fixed bottom-0 end-0 p-3"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
{% with messages = get_flashed_messages(with_categories=true) %}
@ -66,9 +62,14 @@
});
</script>
<script src="{{ url_for('static_bp.serve_js', filename='live.js') }}"></script>
<script src="{{ url_for('static_bp.serve_js', filename='toasts.js') }}"></script>
<script src="{{ url_for('static_bp.serve_js', filename='hide_list.js') }}"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.4/js/lightbox.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.socket.io/4.6.1/socket.io.min.js"></script>
</body>
</html>

View File

@ -2,15 +2,6 @@
{% block title %}Lista: {{ list.title }}{% endblock %}
{% block content %}
<style>
.bg-success {
background-color: #1e7e34 !important;
}
.bg-light {
background-color: #2c2f33 !important;
}
</style>
<div class="d-flex justify-content-between align-items-center mb-3 flex-wrap">
<h2 class="mb-2">
Lista: <strong>{{ list.title }}</strong>
@ -137,8 +128,6 @@ Lista: <strong>{{ list.title }}</strong>
<p><span class="badge bg-secondary">Brak wgranych paragonów do tej listy.</span></p>
{% endif %}
<div id="toast-container" class="toast-container position-fixed bottom-0 end-0 p-3"></div>
<script>
setupList({{ list.id }}, '{{ current_user.username if current_user.is_authenticated else 'Gość' }}');
</script>

View File

@ -2,34 +2,6 @@
{% block title %}Lista: {{ list.title }}{% endblock %}
{% block content %}
<style>
.large-checkbox {
width: 1.5em;
height: 1.5em;
}
.clickable-item {
cursor: pointer;
}
.bg-success {
background-color: #1e7e34 !important;
}
.bg-light {
background-color: #2c2f33 !important;
}
input[type="file"]::file-selector-button {
background-color: #127429;
color: #fff;
border: none;
padding: 0.5em 1em;
border-radius: 4px;
font-weight: bold;
cursor: pointer;
transition: background 0.2s;
}
</style>
<h2 class="mb-2">
🛍️ {{ list.title }}
{% if list.is_archived %}
@ -78,7 +50,6 @@
</div>
{% endif %}
{% if not list.is_archived %}
<hr>
<h5>💰 Dodaj wydatek</h5>
@ -145,7 +116,6 @@
const LIST_ID = {{ list.id }};
setupList(LIST_ID, 'Gość');
</script>
<script src="{{ url_for('static_bp.serve_js', filename='list_guest.js') }}"></script>
{% endblock %}