Add pagination to dataset gallery (50 per page, newest first)
This commit is contained in:
@@ -227,14 +227,34 @@ def dataset_count():
|
||||
|
||||
@app.route("/dataset/list")
|
||||
def dataset_list():
|
||||
"""Lista todas las imágenes del dataset"""
|
||||
"""Lista las imágenes del dataset con paginación"""
|
||||
from flask import request
|
||||
|
||||
try:
|
||||
page = int(request.args.get('page', 1))
|
||||
per_page = int(request.args.get('per_page', 50))
|
||||
|
||||
files = [f for f in os.listdir(DATASET_DIR) if f.endswith('.jpg')]
|
||||
# Ordenar por fecha (más recientes primero)
|
||||
files.sort(reverse=True)
|
||||
|
||||
# Ordenar por fecha de modificación (más recientes primero)
|
||||
files_with_time = []
|
||||
for f in files:
|
||||
filepath = os.path.join(DATASET_DIR, f)
|
||||
mtime = os.path.getmtime(filepath)
|
||||
files_with_time.append((f, mtime))
|
||||
|
||||
files_with_time.sort(key=lambda x: x[1], reverse=True)
|
||||
sorted_files = [f[0] for f in files_with_time]
|
||||
|
||||
# Paginación
|
||||
total = len(sorted_files)
|
||||
total_pages = (total + per_page - 1) // per_page
|
||||
start = (page - 1) * per_page
|
||||
end = start + per_page
|
||||
page_files = sorted_files[start:end]
|
||||
|
||||
images = []
|
||||
for f in files[:50]: # Limitar a últimas 50
|
||||
for f in page_files:
|
||||
parts = f.replace('.jpg', '').split('_')
|
||||
plate = parts[0] if parts else 'Unknown'
|
||||
images.append({
|
||||
@@ -243,7 +263,13 @@ def dataset_list():
|
||||
'url': f'/dataset/images/{f}'
|
||||
})
|
||||
|
||||
return {"images": images, "total": len(files)}
|
||||
return {
|
||||
"images": images,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"per_page": per_page,
|
||||
"total_pages": total_pages
|
||||
}
|
||||
except Exception as e:
|
||||
return {"images": [], "total": 0, "error": str(e)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user