zmiana month na m i poprawka w kolorach paginaci
This commit is contained in:
27
app.py
27
app.py
@@ -1267,17 +1267,38 @@ def favicon():
|
||||
@app.route("/")
|
||||
def main_page():
|
||||
now = datetime.now(timezone.utc)
|
||||
month_str = request.args.get("month") or now.strftime("%Y-%m")
|
||||
|
||||
month_param = request.args.get("month", None) # surowy parametr z URL
|
||||
start = end = None
|
||||
|
||||
if month_str:
|
||||
if month_param in (None, ""):
|
||||
# brak wyboru -> domyślnie aktualny miesiąc
|
||||
month_str = now.strftime("%Y-%m")
|
||||
start = datetime(now.year, now.month, 1, tzinfo=timezone.utc)
|
||||
end = (start + timedelta(days=31)).replace(day=1)
|
||||
|
||||
elif month_param == "all":
|
||||
month_str = "all"
|
||||
start = end = None
|
||||
|
||||
else:
|
||||
month_str = month_param
|
||||
try:
|
||||
year, month = map(int, month_str.split("-"))
|
||||
start = datetime(year, month, 1, tzinfo=timezone.utc)
|
||||
end = (start + timedelta(days=31)).replace(day=1)
|
||||
except:
|
||||
except ValueError:
|
||||
start = end = None
|
||||
|
||||
# dalej normalnie używasz date_filter:
|
||||
def date_filter(query):
|
||||
if start and end:
|
||||
query = query.filter(
|
||||
ShoppingList.created_at >= start,
|
||||
ShoppingList.created_at < end
|
||||
)
|
||||
return query
|
||||
|
||||
def date_filter(query):
|
||||
if start and end:
|
||||
query = query.filter(
|
||||
|
@@ -47,7 +47,9 @@
|
||||
{{ month_names[month|int - 1] }} {{ year }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
<option value="">Wyświetl wszystko</option>
|
||||
<option value="all" {% if selected_month == 'all' %}selected{% endif %}>
|
||||
Wyświetl wszystko
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -235,7 +237,8 @@
|
||||
{{ month_names[month|int - 1] }} {{ year }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
<a href="{{ url_for('main_page') }}" class="btn btn-outline-secondary {% if not selected_month %}active{% endif %}">
|
||||
<a href="{{ url_for('main_page', month='all') }}"
|
||||
class="btn btn-outline-secondary {% if selected_month == 'all' %}active{% endif %}">
|
||||
📋 Wyświetl wszystkie
|
||||
</a>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user