diff --git a/app.py b/app.py index 435b822..59190ad 100644 --- a/app.py +++ b/app.py @@ -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 = ( diff --git a/templates/list.html b/templates/list.html index 2b6433a..1fbc267 100644 --- a/templates/list.html +++ b/templates/list.html @@ -9,10 +9,11 @@ (Archiwalna) {% endif %} - {# Kategorie #} - {% if list.categories %} - {% for cat in list.categories %} - + {% if list.category_badges %} + {% for cat in list.category_badges %} + {{ cat.name }} {% endfor %} @@ -23,6 +24,7 @@ {% endif %} + + {% if list.category_badges %} + {% for cat in list.category_badges %} + {{ cat.name }} {% endfor %} {% endif %} + diff --git a/templates/main.html b/templates/main.html index 1cce537..73c8967 100644 --- a/templates/main.html +++ b/templates/main.html @@ -74,7 +74,16 @@ {% set percent = (purchased_count / total_count * 100) if total_count > 0 else 0 %}
  • - {{ l.title }} (Autor: Ty) + + {{ l.title }} (Autor: Ty) + {% for cat in l.category_badges %} + + {{ cat.name }} + + {% endfor %} +
    📄 Otwórz @@ -118,7 +127,17 @@ {% set percent = (purchased_count / total_count * 100) if total_count > 0 else 0 %}
  • - {{ l.title }} (Autor: {{ l.owner.username }}) + + {{ l.title }} (Autor: {{ l.owner.username }}) + {% for cat in l.category_badges %} + + {{ cat.name }} + + {% endfor %} + + 📄 Otwórz