wizualne
This commit is contained in:
34
app.py
34
app.py
@@ -2847,15 +2847,27 @@ def delete_user(user_id):
|
||||
return redirect(url_for("list_users"))
|
||||
|
||||
|
||||
@app.route("/admin/receipts", defaults={'id': 'all'})
|
||||
@app.route("/admin/receipts/<id>")
|
||||
@app.route("/admin/receipts", methods=["GET"])
|
||||
@app.route("/admin/receipts/<int:list_id>", methods=["GET"])
|
||||
@login_required
|
||||
@admin_required
|
||||
def admin_receipts(id):
|
||||
def admin_receipts(list_id=None):
|
||||
try:
|
||||
page, per_page = get_page_args(default_per_page=24, max_per_page=200)
|
||||
|
||||
if id == "all":
|
||||
if list_id is not None:
|
||||
all_receipts = (
|
||||
Receipt.query.options(joinedload(Receipt.uploaded_by_user))
|
||||
.filter_by(list_id=list_id)
|
||||
.order_by(Receipt.uploaded_at.desc())
|
||||
.all()
|
||||
)
|
||||
receipts_paginated, total_items, total_pages = paginate_items(
|
||||
all_receipts, page, per_page
|
||||
)
|
||||
orphan_files = []
|
||||
id = list_id
|
||||
else:
|
||||
all_filenames = {
|
||||
r.filename for r in Receipt.query.with_entities(Receipt.filename).all()
|
||||
}
|
||||
@@ -2868,6 +2880,7 @@ def admin_receipts(id):
|
||||
|
||||
receipts_paginated = pagination.items
|
||||
total_pages = pagination.pages
|
||||
id = "all"
|
||||
|
||||
upload_folder = app.config["UPLOAD_FOLDER"]
|
||||
files_on_disk = set(os.listdir(upload_folder))
|
||||
@@ -2878,25 +2891,12 @@ def admin_receipts(id):
|
||||
and f not in all_filenames
|
||||
and f.startswith("list_")
|
||||
]
|
||||
else:
|
||||
list_id = int(id)
|
||||
all_receipts = (
|
||||
Receipt.query.options(joinedload(Receipt.uploaded_by_user))
|
||||
.filter_by(list_id=list_id)
|
||||
.order_by(Receipt.uploaded_at.desc())
|
||||
.all()
|
||||
)
|
||||
receipts_paginated, total_items, total_pages = paginate_items(
|
||||
all_receipts, page, per_page
|
||||
)
|
||||
orphan_files = []
|
||||
|
||||
except ValueError:
|
||||
flash("Nieprawidłowe ID listy.", "danger")
|
||||
return redirect(url_for("admin_panel"))
|
||||
|
||||
total_filesize = db.session.query(func.sum(Receipt.filesize)).scalar() or 0
|
||||
|
||||
page_filesize = sum(r.filesize or 0 for r in receipts_paginated)
|
||||
|
||||
query_string = urlencode({k: v for k, v in request.args.items() if k != "page"})
|
||||
|
Reference in New Issue
Block a user