Refactor in the dashboard template

This commit is contained in:
JKuijperM 2026-01-21 15:34:02 +01:00
parent 2b643367e7
commit 182fb01d3c

View File

@ -9,9 +9,50 @@
<body>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<h1>Dashboard</h1>
<!-- ========================= -->
<!-- Filters -->
<!-- ========================= -->
<form method="get">
<label>
Año:
<select name="year">
{% for y in year_list %}
<option value="{{ y }}"
{% if y == selected_year %}selected{% endif %}
>
{{y}}
</option>
{% endfor %}
</select>
</label>
<label>
Mes:
<select name="month">
<option value="">Todos</option>
{% for m in months %}
<option value="{{ m }}"
{% if m == selected_month %}selected{% endif %}
>
{{ m }}
</option>
{% endfor %}
</select>
</label>
<button type="submit">Filtrar</button>
</form>
<hr>
<!-- ========================= -->
<!-- Expenses by category -->
<!-- ========================= -->
<h2>Gastos por categoría</h2>
<ul>
{% for row in by_category %}
<li>{{ row.category__name }} → {{ row.total }}</li>
@ -20,41 +61,28 @@
{% endfor %}
</ul>
<hr>
<!-- ========================= -->
<!-- Expenses by month -->
<!-- ========================= -->
<h2>Gastos por mes</h2>
<ul>
<form method="get">
<label for="year">Año:</label>
<select name="year" id="year">
<option value="">Todos</option>
{% for y in year_list %}
<option value="{{ y.year }}"
{% if selected_year == y.year|stringformat:"s" %}selected{% endif %}
>
{{ y.year }}
</option>
{% for row in by_months %}
<li>Mes {{ row.mont }} → {{ row.total }}</li>
{% endfor %}
</select>
</ul>
<label for="month">Mes:</label>
<select name="month" id="month">
<option value="">Todos</option>
{% for m in months %}
<option value="{{ m }}"
{% if selected_month == m|stringformat:"s" %}selected{% endif %}
>
{{ m }}
</option>
{% endfor %}
</select>
<hr>
<button type="submit">Filtrar</button>
</form>
{% for row in by_month %}
<li>{{ row.month }} → {{ row.total }}</li>
{% endfor %}
<!-- ========================= -->
<!-- Chart -->
<!-- ========================= -->
<canvas id="expensesChart"></canvas>
<script>
const labels = {{ chart_labels|safe }};
const data = {{ chart_data|safe }};
@ -72,6 +100,6 @@
}
});
</script>
</ul>
</body>
</html>