paginacja paragonow

This commit is contained in:
Mateusz Gruszczyński
2025-08-12 23:21:48 +02:00
parent 1e04039387
commit 93a0c32736

26
app.py
View File

@@ -2392,18 +2392,21 @@ def delete_user(user_id):
flash("Użytkownik usunięty", "success")
return redirect(url_for("list_users"))
@app.route("/admin/receipts/<id>")
@login_required
@admin_required
def admin_receipts(id):
try:
if id == "all":
all_filenames = {r.filename for r in Receipt.query.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 = (
receipts_paginated = (
Receipt.query.order_by(Receipt.uploaded_at.desc())
.offset((page - 1) * per_page)
.limit(per_page)
@@ -2411,23 +2414,23 @@ def admin_receipts(id):
)
upload_folder = app.config["UPLOAD_FOLDER"]
all_db_filenames = set(r.filename for r in receipts)
files_on_disk = set(os.listdir(upload_folder))
stale_files = [
orphan_files = [
f
for f in files_on_disk
if f.endswith(".webp")
and f not in all_db_filenames
and f not in all_filenames
and f.startswith("list_")
]
else:
list_id = int(id)
receipts = (
receipts_paginated = (
Receipt.query.filter_by(list_id=list_id)
.order_by(Receipt.uploaded_at.desc())
.all()
)
stale_files = []
orphan_files = []
page = 1
total_pages = 1
except ValueError:
@@ -2436,21 +2439,20 @@ def admin_receipts(id):
args_without_page = request.args.to_dict()
args_without_page.pop("page", None)
query_string = urlencode(args_without_page)
query_string = urlencode(args_without_page)
return render_template(
"admin/receipts.html",
receipts=receipts,
orphan_files=stale_files,
orphan_files_count=len(stale_files),
receipts=receipts_paginated,
orphan_files=orphan_files,
orphan_files_count=len(orphan_files),
page=page,
total_pages=total_pages,
id=id,
query_string=query_string
query_string=query_string,
)
@app.route("/admin/rotate_receipt/<int:receipt_id>")
@login_required
@admin_required