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 = (

View File

@@ -9,10 +9,11 @@
<span class="badge bg-secondary ms-2">(Archiwalna)</span>
{% endif %}
{# Kategorie #}
{% if list.categories %}
{% for cat in list.categories %}
<span class="badge rounded-pill bg-light text-dark border ms-1" style="font-size: 0.75rem; opacity: 0.85;">
{% if list.category_badges %}
{% for cat in list.category_badges %}
<span class="badge rounded-pill text-dark ms-1" style="background-color: {{ cat.color }};
font-size: 0.75rem;
opacity: 0.85;">
{{ cat.name }}
</span>
{% endfor %}
@@ -23,6 +24,7 @@
</a>
{% endif %}
</h2>
</div>
<a href="{{ request.url_root }}share/{{ list.share_token }}" class="btn btn-primary btn-sm w-100 mb-3" {% if not

View File

@@ -20,13 +20,16 @@
{% endif %}
{# Kategorie - tylko wyświetlenie, bez linków #}
{% if list.categories %}
{% for cat in list.categories %}
<span class="badge rounded-pill bg-light text-dark border ms-1" style="font-size: 0.7rem; opacity: 0.85;">
{% if list.category_badges %}
{% for cat in list.category_badges %}
<span class="badge rounded-pill text-dark ms-1" style="background-color: {{ cat.color }};
font-size: 0.75rem;
opacity: 0.85;">
{{ cat.name }}
</span>
{% endfor %}
{% endif %}
</h2>

View File

@@ -74,7 +74,16 @@
{% set percent = (purchased_count / total_count * 100) if total_count > 0 else 0 %}
<li class="list-group-item bg-dark text-white">
<div class="d-flex justify-content-between align-items-center flex-wrap w-100">
<span class="fw-bold">{{ l.title }} (Autor: Ty)</span>
<span class="fw-bold">
{{ l.title }} (Autor: Ty)
{% for cat in l.category_badges %}
<span class="badge rounded-pill text-dark ms-1" style="background-color: {{ cat.color }};
font-size: 0.5rem;
opacity: 0.85;">
{{ cat.name }}
</span>
{% endfor %}
</span>
<div class="btn-group mt-2 mt-md-0" role="group">
<a href="/list/{{ l.id }}" class="btn btn-sm btn-outline-light">📄 Otwórz</a>
@@ -118,7 +127,17 @@
{% set percent = (purchased_count / total_count * 100) if total_count > 0 else 0 %}
<li class="list-group-item bg-dark text-white">
<div class="d-flex justify-content-between align-items-center flex-wrap w-100">
<span class="fw-bold">{{ l.title }} (Autor: {{ l.owner.username }})</span>
<span class="fw-bold">
{{ l.title }} (Autor: {{ l.owner.username }})
{% for cat in l.category_badges %}
<span class="badge rounded-pill text-dark ms-1" style="background-color: {{ cat.color }};
font-size: 0.75rem;
opacity: 0.85;">
{{ cat.name }}
</span>
{% endfor %}
</span>
<a href="/guest-list/{{ l.id }}" class="btn btn-sm btn-outline-light">📄 Otwórz</a>
</div>
<div class="progress progress-dark progress-thin mt-2 position-relative">