diff --git a/app.py b/app.py index 9fcf085..f36b6e8 100644 --- a/app.py +++ b/app.py @@ -1182,6 +1182,10 @@ def file_mtime_filter(path): # return datetime.utcnow() return datetime.now(timezone.utc) +@app.template_filter("todatetime") +def to_datetime_filter(s): + return datetime.strptime(s, "%Y-%m-%d") + @app.template_filter("filesizeformat") def filesizeformat_filter(path): @@ -2126,20 +2130,59 @@ def crop_receipt_user(): @login_required @admin_required def admin_panel(): - now = datetime.now(timezone.utc) + month_str = request.args.get("month") + show_all = (month_str == "all") + + if not show_all: + try: + if month_str: + year, month = map(int, month_str.split("-")) + now = datetime(year, month, 1, tzinfo=timezone.utc) + else: + now = datetime.now(timezone.utc) + month_str = now.strftime("%Y-%m") + except Exception: + now = datetime.now(timezone.utc) + month_str = now.strftime("%Y-%m") + start = now + end = (start + timedelta(days=31)).replace(day=1) + else: + now = datetime.now(timezone.utc) + start = end = None # Liczniki globalne user_count = User.query.count() list_count = ShoppingList.query.count() item_count = Item.query.count() - all_lists = ShoppingList.query.options( + base_query = ShoppingList.query.options( joinedload(ShoppingList.owner), joinedload(ShoppingList.items), joinedload(ShoppingList.receipts), joinedload(ShoppingList.expenses), joinedload(ShoppingList.categories), - ).all() + ) + + if not show_all and start and end: + base_query = base_query.filter(ShoppingList.created_at >= start, ShoppingList.created_at < end) + + 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] all_ids = [l.id for l in all_lists] @@ -2213,6 +2256,7 @@ def admin_panel(): ) purchased_items_count = Item.query.filter_by(purchased=True).count() + expense_summary = get_admin_expense_summary() process = psutil.Process(os.getpid()) app_mem = process.memory_info().rss // (1024 * 1024) @@ -2248,6 +2292,10 @@ def admin_panel(): table_count=table_count, record_total=record_total, uptime_minutes=uptime_minutes, + timedelta=timedelta, + show_all=show_all, + month_str=month_str, + month_options=month_options, ) diff --git a/static/css/style.css b/static/css/style.css index 364f4ba..8a2f76c 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -328,6 +328,7 @@ input.form-control { .ts-dropdown { background-color: #212529 !important; color: #fff !important; + z-index: 9999 !important; } .ts-dropdown .active { diff --git a/templates/admin/admin_panel.html b/templates/admin/admin_panel.html index ec4453b..cbd01c2 100644 --- a/templates/admin/admin_panel.html +++ b/templates/admin/admin_panel.html @@ -127,6 +127,41 @@ +{% if not show_all %} +{% set current_date = now.replace(day=1) %} +{% set prev_month = (current_date - timedelta(days=1)).strftime('%Y-%m') %} +{% set next_month = (current_date + timedelta(days=31)).replace(day=1).strftime('%Y-%m') %} +{% endif %} + +
+
+ {% if not show_all %} + + ← Poprzedni + + + Następny → + + {% endif %} +
+ +
+
+ 📅 + +
+
+
+ +

📄 Wszystkie listy zakupowe

diff --git a/templates/admin/mass_edit_categories.html b/templates/admin/mass_edit_categories.html index ffbca7f..a84d1ec 100644 --- a/templates/admin/mass_edit_categories.html +++ b/templates/admin/mass_edit_categories.html @@ -13,7 +13,7 @@
- +
@@ -57,11 +57,4 @@ {% block scripts %} - - {% endblock %} \ No newline at end of file
ID