usuniecie zbednego kodu i poprawki

This commit is contained in:
Mateusz Gruszczyński
2025-08-15 15:47:32 +02:00
parent 883562c532
commit cc988d5934
2 changed files with 7 additions and 46 deletions

38
app.py
View File

@@ -2835,7 +2835,7 @@ def edit_list(list_id):
@admin_required
def list_products():
page = request.args.get("page", 1, type=int)
per_page = request.args.get("per_page", 125, type=int)
per_page = request.args.get("per_page", 100, type=int)
per_page = max(1, min(per_page, 300))
all_items = (
@@ -2878,40 +2878,10 @@ def list_products():
if name in all_suggestions_dict
}
orphan_suggestions = [
s
for name, s in all_suggestions_dict.items()
s for name, s in all_suggestions_dict.items()
if name not in used_suggestion_names
]
orphan_names_lower = {(s.name or "").strip().lower() for s in orphan_suggestions}
if orphan_names_lower:
items_for_orphans = (
Item.query.filter(func.lower(Item.name).in_(orphan_names_lower))
.filter(Item.added_by.isnot(None))
.options(joinedload(Item.added_by_user))
.order_by(Item.id.desc())
.all()
)
name_to_user = {}
for it in items_for_orphans:
key = (it.name or "").strip().lower()
if key not in name_to_user and it.added_by:
name_to_user[key] = it.added_by
suggestion_added_by_map = {
s.id: name_to_user.get((s.name or "").strip().lower())
for s in orphan_suggestions
}
missing_user_ids = {
uid
for uid in suggestion_added_by_map.values()
if uid and uid not in users_dict
}
if missing_user_ids:
extra_users = User.query.filter(User.id.in_(missing_user_ids)).all()
users_dict.update({u.id: u.username for u in extra_users})
else:
suggestion_added_by_map = {}
query_string = urlencode({k: v for k, v in request.args.items() if k != "page"})
return render_template(
@@ -2920,15 +2890,15 @@ def list_products():
users_dict=users_dict,
suggestions_dict=suggestions_dict,
orphan_suggestions=orphan_suggestions,
suggestion_added_by_map=suggestion_added_by_map,
page=page,
per_page=per_page,
total_pages=total_pages,
query_string=query_string,
total_items=total_items,
total_items=total_items
)
@app.route("/admin/sync_suggestion/<int:item_id>", methods=["POST"])
@login_required
def sync_suggestion_ajax(item_id):