From 01fa938a2700c8f72d37b3e994a6bbd84570e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Wed, 13 Aug 2025 14:46:46 +0200 Subject: [PATCH] zmiana month na m i poprawka w kolorach paginaci --- app.py | 36 ++++++++++++++++++++++-------------- templates/main.html | 33 ++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/app.py b/app.py index 92408e0..6b463d2 100644 --- a/app.py +++ b/app.py @@ -939,6 +939,25 @@ def save_pdf_as_webp(file, path): raise ValueError(f"Błąd podczas przetwarzania PDF: {e}") +def get_active_months_query(visible_lists_query=None): + if db.engine.name == "sqlite": + month_col = func.strftime('%Y-%m', ShoppingList.created_at) + else: + month_col = func.to_char(ShoppingList.created_at, 'YYYY-MM') + + query = db.session.query(month_col.label("month")) + if visible_lists_query is not None: + query = query.select_from(visible_lists_query.subquery()) + + active_months = ( + query.filter(ShoppingList.created_at != None) + .distinct() + .order_by("month") + .all() + ) + return [row.month for row in active_months] + + ############# OCR ########################### @@ -1317,6 +1336,7 @@ def main_page(): .order_by(ShoppingList.created_at.desc()) .all() ) + month_options = get_active_months_query(visible_lists_query) all_lists = user_lists + public_lists + archived_lists all_ids = [l.id for l in all_lists] @@ -1378,6 +1398,7 @@ def main_page(): archived_lists=archived_lists, now=now, timedelta=timedelta, + month_options=month_options ) @@ -2171,20 +2192,7 @@ def admin_panel(): all_lists = base_query.all() # tylko listy z danych miesięcy - if db.engine.name == "sqlite": - month_col = func.strftime('%Y-%m', ShoppingList.created_at) - else: - month_col = func.to_char(ShoppingList.created_at, 'YYYY-MM') - - active_months = ( - db.session.query(month_col.label("month")) - .filter(ShoppingList.created_at != None) - .distinct() - .order_by("month") # bez min() - .all() - ) - - month_options = [row.month for row in active_months] + month_options = get_active_months_query() all_ids = [l.id for l in all_lists] diff --git a/templates/main.html b/templates/main.html index 1f7fed3..12193a4 100644 --- a/templates/main.html +++ b/templates/main.html @@ -33,19 +33,19 @@ {% set month_names = ["styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"] %} -{% set selected_month = request.args.get('month') or now.strftime('%Y-%m') %} +{% set selected_month = selected_month or now.strftime('%Y-%m') %}
@@ -58,6 +58,7 @@
+ {% if current_user.is_authenticated %}

Twoje listy @@ -227,14 +228,16 @@