Update link visibility depending on item number in table
This commit is contained in:
parent
65a35b31f0
commit
2a0fc642b6
3 changed files with 26 additions and 12 deletions
|
@ -19,7 +19,7 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
</form>
|
</form>
|
||||||
{% if snapshots %}
|
{% if not form.instance.adding %}
|
||||||
<h2>{% translate "Statements" %}</h2>
|
<h2>{% translate "Statements" %}</h2>
|
||||||
{% include "main/table/snapshot.html" %}
|
{% include "main/table/snapshot.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if snapshot.transaction_set.all %}
|
{% if not snapshot.adding %}
|
||||||
<h2>{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
|
<h2>{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
|
||||||
{% include "main/table/transaction.html" %}
|
{% include "main/table/transaction.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -134,18 +134,27 @@ class AccountUpdateView(NummiUpdateView):
|
||||||
form_class = AccountForm
|
form_class = AccountForm
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
_max = 8
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
account = data["form"].instance
|
account = data["form"].instance
|
||||||
return data | {
|
|
||||||
"transactions": account.transaction_set.all()[:8],
|
_transactions = account.transaction_set.all()
|
||||||
"transactions_url": reverse_lazy(
|
if _transactions.count() > _max:
|
||||||
|
data["transactions_url"] = reverse_lazy(
|
||||||
"account_transactions", args=(account.pk,)
|
"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(
|
"new_snapshot_url": reverse_lazy(
|
||||||
"snapshot", kwargs={"account": account.pk}
|
"snapshot", kwargs={"account": account.pk}
|
||||||
),
|
),
|
||||||
"snapshots": account.snapshot_set.all()[:8],
|
"snapshots": _snapshots[:8],
|
||||||
"snapshots_url": reverse_lazy("account_snapshots", args=(account.pk,)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,16 +202,21 @@ class SnapshotUpdateView(NummiUpdateView):
|
||||||
form_class = SnapshotForm
|
form_class = SnapshotForm
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
_max = 8
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
snapshot = data["form"].instance
|
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 | {
|
return data | {
|
||||||
"new_transaction_url": reverse_lazy(
|
"new_transaction_url": reverse_lazy(
|
||||||
"transaction", kwargs={"snapshot": snapshot.pk}
|
"transaction", kwargs={"snapshot": snapshot.pk}
|
||||||
),
|
),
|
||||||
"transactions": snapshot.transaction_set.all()[:8],
|
"transactions": _transactions[:_max],
|
||||||
"transactions_url": reverse_lazy(
|
|
||||||
"snapshot_transactions", args=(snapshot.pk,)
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue