Only show all transactions line when number is strictly higher than showed

This commit is contained in:
Edgar P. Burkhart 2022-12-31 11:13:46 +01:00
parent 7c5e804aba
commit 2a898c706e
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -26,19 +26,22 @@ class IndexView(LoginRequiredMixin, TemplateView):
template_name = "main/index.html" template_name = "main/index.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
_max = 10 _max = 8
res = super().get_context_data(**kwargs) | { _transactions = Transaction.objects.filter(user=self.request.user)
_snapshots = Snapshot.objects.filter(user=self.request.user)
res = {
"accounts": Account.objects.filter(user=self.request.user), "accounts": Account.objects.filter(user=self.request.user),
"transactions": Transaction.objects.filter(user=self.request.user)[:10], "transactions": _transactions[:_max],
"categories": Category.objects.filter(user=self.request.user), "categories": Category.objects.filter(user=self.request.user),
"snapshots": Snapshot.objects.filter(user=self.request.user)[:10], "snapshots": _snapshots[:_max],
} }
if res["transactions"].count() == 10: if _transactions.count() > _max:
res["transactions_url"] = reverse_lazy("transactions") res["transactions_url"] = reverse_lazy("transactions")
if res["snapshots"].count() == 10: if _snapshots.count() > _max:
res["snapshots_url"] = reverse_lazy("snapshots") res["snapshots_url"] = reverse_lazy("snapshots")
return res return super().get_context_data(**kwargs) | res
class UserMixin(LoginRequiredMixin): class UserMixin(LoginRequiredMixin):