paginacja paragonow
This commit is contained in:
23
app.py
23
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/<id>")
|
||||
@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,
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user