wersja 0.0.4 #7

Merged
gru merged 47 commits from zliczanie_wydatkow_i_poprawki_w_js into master 2025-07-28 22:17:13 +02:00
3 changed files with 44 additions and 18 deletions
Showing only changes of commit bb667a2cbd - Show all commits

44
app.py
View File

@@ -958,17 +958,25 @@ def view_list(list_id):
def user_expenses():
start_date_str = request.args.get("start_date")
end_date_str = request.args.get("end_date")
show_all = request.args.get("show_all", "false").lower() == "true"
start = None
end = None
# Przygotowanie podstawowego zapytania o wydatki użytkownika
expenses_query = (
Expense.query.join(ShoppingList, Expense.list_id == ShoppingList.id)
.options(joinedload(Expense.list))
.filter(ShoppingList.owner_id == current_user.id)
)
expenses_query = Expense.query.join(
ShoppingList, Expense.list_id == ShoppingList.id
).options(joinedload(Expense.list))
# Jeśli show_all to False, filtruj tylko po bieżącym użytkowniku
if not show_all:
expenses_query = expenses_query.filter(ShoppingList.owner_id == current_user.id)
else:
expenses_query = expenses_query.filter(
or_(
ShoppingList.owner_id == current_user.id, ShoppingList.is_public == True
)
)
# Filtrowanie po zakresie dat, jeśli podano
if start_date_str and end_date_str:
try:
start = datetime.strptime(start_date_str, "%Y-%m-%d")
@@ -981,7 +989,13 @@ def user_expenses():
expenses = expenses_query.order_by(Expense.added_at.desc()).all()
# Tabela wydatków
list_ids = {e.list_id for e in expenses}
lists = (
ShoppingList.query.filter(ShoppingList.id.in_(list_ids))
.order_by(ShoppingList.created_at.desc())
.all()
)
expense_table = [
{
"title": e.list.title if e.list else "Nieznana",
@@ -991,15 +1005,6 @@ def user_expenses():
for e in expenses
]
# Tylko listy z tych wydatków
list_ids = {e.list_id for e in expenses}
lists = (
ShoppingList.query.filter(ShoppingList.id.in_(list_ids))
.order_by(ShoppingList.created_at.desc())
.all()
)
# Lista zsumowanych wydatków per lista (z uwzględnieniem filtra dat)
lists_data = [
{
"id": l.id,
@@ -1016,7 +1021,10 @@ def user_expenses():
]
return render_template(
"user_expenses.html", expense_table=expense_table, lists_data=lists_data
"user_expenses.html",
expense_table=expense_table,
lists_data=lists_data,
show_all=show_all,
)

View File

@@ -115,6 +115,8 @@ document.addEventListener("DOMContentLoaded", function () {
});
toggleBtn.textContent = allChecked ? "🚫 Odznacz wszystkie" : "✅ Zaznacz wszystkie";
const updateTotalEvent = new Event('change');
checkboxes.forEach(cb => cb.dispatchEvent(updateTotalEvent));
});
});
@@ -125,4 +127,15 @@ document.getElementById("applyCustomRange")?.addEventListener("click", () => {
const url = `/user_expenses?start_date=${start}&end_date=${end}`;
window.location.href = url;
}
});
document.getElementById("showAllLists").addEventListener("change", function () {
const checked = this.checked;
const url = new URL(window.location.href);
if (checked) {
url.searchParams.set("show_all", "true");
} else {
url.searchParams.delete("show_all");
}
window.location.href = url.toString();
});

View File

@@ -47,6 +47,11 @@
<label class="form-check-label ms-2 text-white" for="onlyWithExpenses">Pokaż tylko listy z
wydatkami</label>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="showAllLists" {% if show_all %}checked{% endif %}>
<label class="form-check-label ms-2 text-white" for="showAllLists">Pokaż wszystkie publiczne listy
innych</label>
</div>
<div class="input-group input-group-sm mb-3 w-100" style="max-width: 570px;">
<span class="input-group-text bg-secondary text-white border-secondary">Od</span>