paginacja i poprawki uxowe

This commit is contained in:
Mateusz Gruszczyński
2025-08-15 10:14:33 +02:00
parent b61c262179
commit 4955516c93

30
app.py
View File

@@ -45,7 +45,7 @@ from config import Config
from PIL import Image, ExifTags, ImageFilter, ImageOps
from werkzeug.middleware.proxy_fix import ProxyFix
from sqlalchemy import func, extract, inspect, or_, case, text
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import joinedload, load_only
from collections import defaultdict, deque
from functools import wraps
@@ -2845,19 +2845,22 @@ def list_products():
pagination = items_query.paginate(page=page, per_page=per_page, error_out=False)
items = pagination.items
users = User.query.all()
users_dict = {user.id: user.username for user in users}
item_names_subquery = db.session.query(
func.lower(func.trim(Item.name)).label("normalized_name")
).distinct().subquery()
suggestions = SuggestedProduct.query.order_by(SuggestedProduct.name.asc()).all()
all_suggestions_dict = {
(s.name or "").strip().lower(): s for s in suggestions if s.name and s.name.strip()
(s.name or "").strip().lower(): s
for s in suggestions
if s.name and s.name.strip()
}
used_suggestion_names = {(item.name or "").strip().lower() for item in items if item.name}
orphan_suggestions = [
s for s in suggestions
if (s.name or "").strip().lower() not in used_suggestion_names and (s.name or "").strip()
]
used_suggestion_names = {
row.normalized_name for row in db.session.query(item_names_subquery)
if row.normalized_name
}
suggestions_dict = {
name: all_suggestions_dict[name]
@@ -2865,6 +2868,14 @@ def list_products():
if name in all_suggestions_dict
}
orphan_suggestions = [
s for name, s in all_suggestions_dict.items()
if name not in used_suggestion_names
]
users = User.query.options(load_only(User.id, User.username)).all()
users_dict = {user.id: user.username for user in users}
query_string = urlencode({k: v for k, v in request.args.items() if k != "page"})
return render_template(
@@ -2881,6 +2892,7 @@ def list_products():
@app.route("/admin/sync_suggestion/<int:item_id>", methods=["POST"])
@login_required
def sync_suggestion_ajax(item_id):