Update all transaction lists

This commit is contained in:
Edgar P. Burkhart 2022-12-31 11:25:46 +01:00
parent 2a898c706e
commit 7f4b6a0415
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
5 changed files with 43 additions and 6 deletions

View file

@ -19,4 +19,5 @@
{% csrf_token %}
{{ form }}
</form>
{% include "main/table/transaction.html" %}
{% endblock %}

View file

@ -23,8 +23,6 @@
<img src="{% url "plot-category" form.instance.id %}"
alt="Graph representing value over time"/>
<h2>{% translate "Transactions" %}</h2>
{% with transactions=form.instance.transactions %}
{% include "main/table/transaction.html" %}
{% endwith %}
{% include "main/table/transaction.html" %}
{% endif %}
{% endblock %}

View file

@ -73,9 +73,7 @@
{% endif %}
{% if snapshot.transaction_set.all %}
<h2>{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
{% with transactions=snapshot.transaction_set.all %}
{% include "main/table/transaction.html" %}
{% endwith %}
{% include "main/table/transaction.html" %}
{% endif %}
{% endwith %}
{% endblock %}

View file

@ -35,6 +35,11 @@ urlpatterns = [
name="invoice",
),
path("category/<pk>", views.CategoryUpdateView.as_view(), name="category"),
path(
"category/<pk>/transactions",
views.CategoryTListView.as_view(),
name="category_transactions",
),
path("snapshot/<pk>", views.SnapshotUpdateView.as_view(), name="snapshot"),
path(
"snapshot/<pk>/transactions",

View file

@ -120,6 +120,16 @@ class AccountUpdateView(NummiUpdateView):
model = Account
form_class = AccountForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
account = data["form"].instance
return data | {
"transactions": account.transaction_set.all()[:8],
"transactions_url": reverse_lazy(
"account_transactions", args=(account.pk,)
),
}
class TransactionUpdateView(NummiUpdateView):
model = Transaction
@ -149,11 +159,31 @@ class CategoryUpdateView(NummiUpdateView):
model = Category
form_class = CategoryForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
category = data["form"].instance
return data | {
"transactions": category.transaction_set.all()[:8],
"transactions_url": reverse_lazy(
"category_transactions", args=(category.pk,)
),
}
class SnapshotUpdateView(NummiUpdateView):
model = Snapshot
form_class = SnapshotForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
snapshot = data["form"].instance
return data | {
"transactions": snapshot.transaction_set.all()[:8],
"transactions_url": reverse_lazy(
"snapshot_transactions", args=(snapshot.pk,)
),
}
class AccountDeleteView(NummiDeleteView):
model = Account
@ -217,6 +247,11 @@ class SnapshotTListView(TransactionListView):
return super().get_queryset().filter(snapshot=self.kwargs.get("pk"))
class CategoryTListView(TransactionListView):
def get_queryset(self):
return super().get_queryset().filter(category=self.kwargs.get("pk"))
class SearchView(TransactionListView):
def post(self, *args, **kwargs):
return redirect("search", search=self.request.POST.get("search"))