badge kategorii

This commit is contained in:
Mateusz Gruszczyński
2025-08-01 14:24:25 +02:00
parent beed40868d
commit 3f67007f2f
4 changed files with 50 additions and 11 deletions

19
app.py
View File

@@ -1327,11 +1327,11 @@ def main_page():
.all()
)
# Dodajemy statystyki
all_lists = user_lists + public_lists + archived_lists
all_ids = [l.id for l in all_lists]
if all_ids:
# statystyki produktów
stats = (
db.session.query(
Item.list_id,
@@ -1348,7 +1348,6 @@ def main_page():
s.list_id: (s.total_count or 0, s.purchased_count or 0) for s in stats
}
# ostatnia kwota (w tym przypadku max = suma z ostatniego zapisu)
latest_expenses_map = dict(
db.session.query(
Expense.list_id, func.coalesce(func.sum(Expense.amount), 0)
@@ -1363,11 +1362,17 @@ def main_page():
l.total_count = total_count
l.purchased_count = purchased_count
l.total_expense = latest_expenses_map.get(l.id, 0)
l.category_badges = [
{"name": c.name, "color": category_to_color(c.name)}
for c in l.categories
]
else:
for l in all_lists:
l.total_count = 0
l.purchased_count = 0
l.total_expense = 0
l.category_badges = []
return render_template(
"main.html",
@@ -1641,6 +1646,11 @@ def view_list(list_id):
else:
item.added_by_display = None
shopping_list.category_badges = [
{"name": c.name, "color": category_to_color(c.name)}
for c in shopping_list.categories
]
return render_template(
"list.html",
list=shopping_list,
@@ -1826,6 +1836,11 @@ def shared_list(token=None, list_id=None):
list_id
)
shopping_list.category_badges = [
{"name": c.name, "color": category_to_color(c.name)}
for c in shopping_list.categories
]
for item in items:
if item.added_by != shopping_list.owner_id:
item.added_by_display = (