From a224ec1c2a9bf38acdb92f168f2ee5685b6dfcd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Tue, 12 Aug 2025 23:08:07 +0200 Subject: [PATCH] paginacja paragonow --- app.py | 23 +++++++++++++++++++++-- templates/admin/receipts.html | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index e05f3f3..4ae63b1 100644 --- a/app.py +++ b/app.py @@ -2392,14 +2392,24 @@ def delete_user(user_id): flash("Użytkownik usunięty", "success") return redirect(url_for("list_users")) - @app.route("/admin/receipts/") @login_required @admin_required def admin_receipts(id): try: if id == "all": - receipts = Receipt.query.order_by(Receipt.uploaded_at.desc()).all() + per_page = 24 + page = request.args.get("page", 1, type=int) + total_count = Receipt.query.count() + total_pages = (total_count + per_page - 1) // per_page + + receipts = ( + Receipt.query.order_by(Receipt.uploaded_at.desc()) + .offset((page - 1) * per_page) + .limit(per_page) + .all() + ) + upload_folder = app.config["UPLOAD_FOLDER"] all_db_filenames = set(r.filename for r in receipts) files_on_disk = set(os.listdir(upload_folder)) @@ -2418,15 +2428,24 @@ def admin_receipts(id): .all() ) stale_files = [] + page = 1 + total_pages = 1 except ValueError: flash("Nieprawidłowe ID listy.", "danger") return redirect(url_for("admin_panel")) + args_without_page = request.args.to_dict() + args_without_page.pop('page', None) + return render_template( "admin/receipts.html", receipts=receipts, orphan_files=stale_files, orphan_files_count=len(stale_files), + page=page, + total_pages=total_pages, + id=id, + args_without_page=args_without_page, ) diff --git a/templates/admin/receipts.html b/templates/admin/receipts.html index 97cb5c0..def3d53 100644 --- a/templates/admin/receipts.html +++ b/templates/admin/receipts.html @@ -66,6 +66,32 @@ + + + {% if orphan_files and request.path.endswith('/all') %}

Znalezione nieprzypisane pliki ({{ orphan_files_count }})