Add transaction list views for snapshots and accounts (#4)

This commit is contained in:
Edgar P. Burkhart 2022-12-31 10:12:37 +01:00
parent 4e6dd25c99
commit acd83704af
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 23 additions and 8 deletions

View file

@ -17,6 +17,11 @@ urlpatterns = [
path("category", views.CategoryCreateView.as_view(), name="category"), path("category", views.CategoryCreateView.as_view(), name="category"),
path("snapshot", views.SnapshotCreateView.as_view(), name="snapshot"), path("snapshot", views.SnapshotCreateView.as_view(), name="snapshot"),
path("account/<pk>", views.AccountUpdateView.as_view(), name="account"), path("account/<pk>", views.AccountUpdateView.as_view(), name="account"),
path(
"account/<pk>/transactions",
views.AccountTListView.as_view(),
name="account_transactions",
),
path("transaction/<pk>", views.TransactionUpdateView.as_view(), name="transaction"), path("transaction/<pk>", views.TransactionUpdateView.as_view(), name="transaction"),
path( path(
"transaction/<transaction_pk>/invoice/<pk>", "transaction/<transaction_pk>/invoice/<pk>",
@ -25,6 +30,11 @@ urlpatterns = [
), ),
path("category/<pk>", views.CategoryUpdateView.as_view(), name="category"), path("category/<pk>", views.CategoryUpdateView.as_view(), name="category"),
path("snapshot/<pk>", views.SnapshotUpdateView.as_view(), name="snapshot"), path("snapshot/<pk>", views.SnapshotUpdateView.as_view(), name="snapshot"),
path(
"snapshot/<pk>/transactions",
views.SnapshotTListView.as_view(),
name="snapshot_transactions",
),
path( path(
"account/<pk>/delete", "account/<pk>/delete",
views.AccountDeleteView.as_view(), views.AccountDeleteView.as_view(),

View file

@ -71,13 +71,6 @@ class LogoutView(auth_views.LogoutView):
next_page = "login" next_page = "login"
class TransactionListView(UserMixin, ListView):
paginate_by = 24
model = Transaction
template_name = "main/transactions.html"
context_object_name = "transactions"
class AccountCreateView(NummiCreateView): class AccountCreateView(NummiCreateView):
model = Account model = Account
form_class = AccountForm form_class = AccountForm
@ -180,12 +173,24 @@ class SnapshotDeleteView(NummiDeleteView):
model = Snapshot model = Snapshot
class SearchView(UserMixin, UserFormMixin, ListView): class TransactionListView(UserMixin, ListView):
paginate_by = 24 paginate_by = 24
model = Transaction model = Transaction
template_name = "main/transactions.html" template_name = "main/transactions.html"
context_object_name = "transactions" 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): def post(self, *args, **kwargs):
return redirect("search", search=self.request.POST.get("search")) return redirect("search", search=self.request.POST.get("search"))