duzo zmian ux w panelu
This commit is contained in:
64
app.py
64
app.py
@@ -2834,21 +2834,53 @@ def edit_list(list_id):
|
||||
@login_required
|
||||
@admin_required
|
||||
def list_products():
|
||||
items = Item.query.order_by(Item.id.desc()).all()
|
||||
users = db.session.query(User).all()
|
||||
items = Item.query.options(
|
||||
joinedload(Item.shopping_list),
|
||||
joinedload(Item.added_by_user),
|
||||
).order_by(Item.id.desc()).all()
|
||||
|
||||
users = User.query.all()
|
||||
users_dict = {user.id: user.username for user in users}
|
||||
|
||||
suggestions = SuggestedProduct.query.order_by(SuggestedProduct.name.asc()).all()
|
||||
suggestions_dict = {s.name.lower(): s for s in suggestions}
|
||||
all_suggestions_dict = {
|
||||
(s.name or "").strip().lower(): s for s in suggestions if s.name and s.name.strip()
|
||||
}
|
||||
|
||||
seen_names = set()
|
||||
unique_items = []
|
||||
used_suggestion_names = set()
|
||||
|
||||
for item in items:
|
||||
normalized_name = (item.name or "").strip().lower()
|
||||
if not normalized_name:
|
||||
continue
|
||||
if normalized_name not in seen_names:
|
||||
seen_names.add(normalized_name)
|
||||
unique_items.append(item)
|
||||
used_suggestion_names.add(normalized_name)
|
||||
|
||||
orphan_suggestions = [
|
||||
s for s in suggestions
|
||||
if (s.name or "").strip().lower() not in used_suggestion_names and (s.name or "").strip()
|
||||
]
|
||||
|
||||
suggestions_dict = {
|
||||
name: all_suggestions_dict[name]
|
||||
for name in used_suggestion_names
|
||||
if name in all_suggestions_dict
|
||||
}
|
||||
|
||||
return render_template(
|
||||
"admin/list_products.html",
|
||||
items=items,
|
||||
items=unique_items,
|
||||
users_dict=users_dict,
|
||||
suggestions_dict=suggestions_dict,
|
||||
orphan_suggestions=orphan_suggestions,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@app.route("/admin/sync_suggestion/<int:item_id>", methods=["POST"])
|
||||
@login_required
|
||||
def sync_suggestion_ajax(item_id):
|
||||
@@ -2954,25 +2986,37 @@ def recalculate_filesizes_all():
|
||||
@admin_required
|
||||
def admin_mass_edit_categories():
|
||||
lists = (
|
||||
ShoppingList.query.options(joinedload(ShoppingList.categories))
|
||||
ShoppingList.query.options(
|
||||
joinedload(ShoppingList.categories),
|
||||
joinedload(ShoppingList.items),
|
||||
joinedload(ShoppingList.owner),
|
||||
)
|
||||
.order_by(ShoppingList.created_at.desc())
|
||||
.all()
|
||||
)
|
||||
|
||||
categories = Category.query.order_by(Category.name.asc()).all()
|
||||
|
||||
for l in lists:
|
||||
l.total_count = len(l.items)
|
||||
l.owner_name = l.owner.username if l.owner else "?"
|
||||
l.category_count = len(l.categories)
|
||||
|
||||
if request.method == "POST":
|
||||
for lst in lists:
|
||||
selected_ids = request.form.getlist(f"categories_{lst.id}")
|
||||
lst.categories.clear()
|
||||
for l in lists:
|
||||
selected_ids = request.form.getlist(f"categories_{l.id}")
|
||||
l.categories.clear()
|
||||
if selected_ids:
|
||||
cats = Category.query.filter(Category.id.in_(selected_ids)).all()
|
||||
lst.categories.extend(cats)
|
||||
l.categories.extend(cats)
|
||||
db.session.commit()
|
||||
flash("Zaktualizowano kategorie dla wybranych list", "success")
|
||||
return redirect(url_for("admin_mass_edit_categories"))
|
||||
|
||||
return render_template(
|
||||
"admin/mass_edit_categories.html", lists=lists, categories=categories
|
||||
"admin/mass_edit_categories.html",
|
||||
lists=lists,
|
||||
categories=categories
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user