Add last statements to home page

This commit is contained in:
Edgar P. Burkhart 2024-12-31 15:31:07 +01:00
parent c754e869fc
commit 412cf94f93
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 23 additions and 15 deletions

View file

@ -336,6 +336,7 @@ ul.messages {
.accounts {
display: grid;
grid-row-gap: 0.5rem;
grid-auto-rows: min-content;
dl {
margin: 0;

View file

@ -30,6 +30,11 @@
</div>
<a href="{% url "new_account" %}">{% translate "Create account" %}</a>
</section>
<section class="statements">
<h2>{% translate "Statements" %}</h2>
{% include "statement/statement_table.html" %}
</section>
</div>
<section class="categories">
<h2>{% translate "Categories" %}</h2>
{% spaceless %}
@ -41,7 +46,6 @@
</p>
{% endspaceless %}
</section>
</div>
{% if history %}
<section>
<h2>{% translate "History" %}</h2>

View file

@ -25,19 +25,22 @@ class IndexView(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs):
_max = 8
_transactions = Transaction.objects.filter(user=self.request.user)
_statements = Statement.objects.filter(user=self.request.user)
_accounts = Account.objects.filter(user=self.request.user)
_statements = (
Statement.objects.filter(user=self.request.user)
.exclude(account__archived=True)
.order_by("account__id", "-date")
.distinct("account__id")
)
res = {
"accounts": _accounts,
"transactions": _transactions[:_max],
"categories": Category.objects.filter(user=self.request.user),
"statements": _statements[:_max],
"statements": _statements,
"history": history(_transactions.exclude(category__budget=False)),
}
if _transactions.count() > _max:
res["transactions_url"] = reverse_lazy("transactions")
if _statements.count() > _max:
res["statements_url"] = reverse_lazy("statements")
return super().get_context_data(**kwargs) | res