From 4955516c93d98e5457986b1b6b0c6ebc4f7a325e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 15 Aug 2025 10:14:33 +0200 Subject: [PATCH] paginacja i poprawki uxowe --- app.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index a58a990..7cc794e 100644 --- a/app.py +++ b/app.py @@ -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/", methods=["POST"]) @login_required def sync_suggestion_ajax(item_id):