From 8f14c20d5544a156fc7d679d90f844f895ddeab4 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sat, 31 Dec 2022 10:12:37 +0100 Subject: [PATCH] Add transaction list views for snapshots and accounts --- nummi/main/urls.py | 10 ++++++++++ nummi/main/views.py | 21 +++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/nummi/main/urls.py b/nummi/main/urls.py index d4abfe1..c672c07 100644 --- a/nummi/main/urls.py +++ b/nummi/main/urls.py @@ -17,6 +17,11 @@ urlpatterns = [ path("category", views.CategoryCreateView.as_view(), name="category"), path("snapshot", views.SnapshotCreateView.as_view(), name="snapshot"), path("account/", views.AccountUpdateView.as_view(), name="account"), + path( + "account//transactions", + views.AccountTListView.as_view(), + name="account_transactions", + ), path("transaction/", views.TransactionUpdateView.as_view(), name="transaction"), path( "transaction//invoice/", @@ -25,6 +30,11 @@ urlpatterns = [ ), path("category/", views.CategoryUpdateView.as_view(), name="category"), path("snapshot/", views.SnapshotUpdateView.as_view(), name="snapshot"), + path( + "snapshot//transactions", + views.SnapshotTListView.as_view(), + name="snapshot_transactions", + ), path( "account//delete", views.AccountDeleteView.as_view(), diff --git a/nummi/main/views.py b/nummi/main/views.py index 3c24222..72806be 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -71,13 +71,6 @@ class LogoutView(auth_views.LogoutView): next_page = "login" -class TransactionListView(UserMixin, ListView): - paginate_by = 24 - model = Transaction - template_name = "main/transactions.html" - context_object_name = "transactions" - - class AccountCreateView(NummiCreateView): model = Account form_class = AccountForm @@ -180,12 +173,24 @@ class SnapshotDeleteView(NummiDeleteView): model = Snapshot -class SearchView(UserMixin, UserFormMixin, ListView): +class TransactionListView(UserMixin, ListView): paginate_by = 24 model = Transaction template_name = "main/transactions.html" context_object_name = "transactions" + +class AccountTListView(TransactionListView): + def get_queryset(self): + return super().get_queryset().filter(account=self.kwargs.get("pk")) + + +class SnapshotTListView(TransactionListView): + def get_queryset(self): + return super().get_queryset().filter(snapshot=self.kwargs.get("pk")) + + +class SearchView(TransactionListView): def post(self, *args, **kwargs): return redirect("search", search=self.request.POST.get("search"))