Update link visibility depending on item number in table

This commit is contained in:
Edgar P. Burkhart 2022-12-31 12:12:15 +01:00
parent 65a35b31f0
commit 2a0fc642b6
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 26 additions and 12 deletions

View file

@ -19,7 +19,7 @@
{% csrf_token %}
{{ form }}
</form>
{% if snapshots %}
{% if not form.instance.adding %}
<h2>{% translate "Statements" %}</h2>
{% include "main/table/snapshot.html" %}
{% endif %}

View file

@ -71,7 +71,7 @@
{% endfor %}
</div>
{% endif %}
{% if snapshot.transaction_set.all %}
{% if not snapshot.adding %}
<h2>{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
{% include "main/table/transaction.html" %}
{% endif %}

View file

@ -134,18 +134,27 @@ class AccountUpdateView(NummiUpdateView):
form_class = AccountForm
def get_context_data(self, **kwargs):
_max = 8
data = super().get_context_data(**kwargs)
account = data["form"].instance
return data | {
"transactions": account.transaction_set.all()[:8],
"transactions_url": reverse_lazy(
_transactions = account.transaction_set.all()
if _transactions.count() > _max:
data["transactions_url"] = reverse_lazy(
"account_transactions", args=(account.pk,)
),
)
_snapshots = account.snapshot_set.all()
if _snapshots.count() > _max:
data["snapshots_url"] = reverse_lazy(
"account_snapshots", args=(account.pk,)
)
return data | {
"transactions": _transactions[:8],
"new_snapshot_url": reverse_lazy(
"snapshot", kwargs={"account": account.pk}
),
"snapshots": account.snapshot_set.all()[:8],
"snapshots_url": reverse_lazy("account_snapshots", args=(account.pk,)),
"snapshots": _snapshots[:8],
}
@ -193,16 +202,21 @@ class SnapshotUpdateView(NummiUpdateView):
form_class = SnapshotForm
def get_context_data(self, **kwargs):
_max = 8
data = super().get_context_data(**kwargs)
snapshot = data["form"].instance
_transactions = snapshot.transaction_set.all()
if _transactions.count() > _max:
data["transactions_url"] = reverse_lazy(
"snapshot_transactions", args=(snapshot.pk,)
)
return data | {
"new_transaction_url": reverse_lazy(
"transaction", kwargs={"snapshot": snapshot.pk}
),
"transactions": snapshot.transaction_set.all()[:8],
"transactions_url": reverse_lazy(
"snapshot_transactions", args=(snapshot.pk,)
),
"transactions": _transactions[:_max],
}