From 057734afd3238d7bb15bacc298d6053bab409267 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sat, 31 Dec 2022 10:27:06 +0100 Subject: [PATCH] Add snapshot list view, general and per account Closes #4 --- nummi/main/templates/main/index.html | 42 +----------------- nummi/main/templates/main/snapshots.html | 36 ++++++++++++++++ .../templates/main/tag/snapshot_table.html | 43 +++++++++++++++++++ nummi/main/templatetags/main_extras.py | 5 +++ nummi/main/urls.py | 6 +++ nummi/main/views.py | 23 ++++++++-- 6 files changed, 111 insertions(+), 44 deletions(-) create mode 100644 nummi/main/templates/main/snapshots.html create mode 100644 nummi/main/templates/main/tag/snapshot_table.html diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html index 3d94a7a..e9e321b 100644 --- a/nummi/main/templates/main/index.html +++ b/nummi/main/templates/main/index.html @@ -43,46 +43,6 @@ {% endif %} {% if snapshots %}

{% translate "Snapshots" %}

-
-
- - {% translate "Date" %} - - {% translate "Value" %} - {% translate "Difference" %} - {% translate "Transactions" %} - {% translate "Valid" %} -
- {% for snap in snapshots %} -
- - {% if snap.file %} - - - - {% endif %} - - - {{ snap.date|date:"Y-m-d" }} - - - {{ snap.value|value }} - {{ snap.diff|pmvalue }} - {% with sum=snap.sum %} - {{ sum|pmvalue }} - - {% if sum == snap.diff %} - - {% else %} - - {% endif %} - - {% endwith %} -
- {% endfor %} -
+ {% snapshot_table snapshots %} {% endif %} {% endblock %} diff --git a/nummi/main/templates/main/snapshots.html b/nummi/main/templates/main/snapshots.html new file mode 100644 index 0000000..bf0c461 --- /dev/null +++ b/nummi/main/templates/main/snapshots.html @@ -0,0 +1,36 @@ +{% extends "main/base.html" %} +{% load static %} +{% load main_extras %} +{% load i18n %} +{% block link %} + {{ block.super }} + + +{% endblock %} +{% block body %} +

{% translate "Statements" %}

+ {% if snapshots %} + {% snapshot_table snapshots %} + {% if page_obj %} + + {% endif %} + {% else %} +

{% translate "No snapshots to show" %}

+ {% endif %} +{% endblock %} diff --git a/nummi/main/templates/main/tag/snapshot_table.html b/nummi/main/templates/main/tag/snapshot_table.html new file mode 100644 index 0000000..a4ea80f --- /dev/null +++ b/nummi/main/templates/main/tag/snapshot_table.html @@ -0,0 +1,43 @@ +{% load main_extras %} +{% load i18n %} +
+
+ + {% translate "Date" %} + + {% translate "Value" %} + {% translate "Difference" %} + {% translate "Transactions" %} + {% translate "Valid" %} +
+ {% for snap in snapshots %} +
+ + {% if snap.file %} + + + + {% endif %} + + + {{ snap.date|date:"Y-m-d" }} + + + {{ snap.value|value }} + {{ snap.diff|pmvalue }} + {% with sum=snap.sum %} + {{ sum|pmvalue }} + + {% if sum == snap.diff %} + + {% else %} + + {% endif %} + + {% endwith %} +
+ {% endfor %} +
diff --git a/nummi/main/templatetags/main_extras.py b/nummi/main/templatetags/main_extras.py index 41978d7..6205a59 100644 --- a/nummi/main/templatetags/main_extras.py +++ b/nummi/main/templatetags/main_extras.py @@ -33,6 +33,11 @@ def transaction_table(transactions): return {"transactions": transactions} +@register.inclusion_tag("main/tag/snapshot_table.html") +def snapshot_table(snapshots): + return {"snapshots": snapshots} + + @register.inclusion_tag("main/tag/form_buttons.html") def form_buttons(instance): return { diff --git a/nummi/main/urls.py b/nummi/main/urls.py index c672c07..0bbb210 100644 --- a/nummi/main/urls.py +++ b/nummi/main/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path("login", views.LoginView.as_view(), name="login"), path("logout", views.LogoutView.as_view(), name="logout"), path("transactions", views.TransactionListView.as_view(), name="transactions"), + path("snapshots", views.SnapshotListView.as_view(), name="snapshots"), path("account", views.AccountCreateView.as_view(), name="account"), path("transaction", views.TransactionCreateView.as_view(), name="transaction"), path( @@ -22,6 +23,11 @@ urlpatterns = [ views.AccountTListView.as_view(), name="account_transactions", ), + path( + "account//snapshots", + views.AccountSListView.as_view(), + name="account_snapshots", + ), path("transaction/", views.TransactionUpdateView.as_view(), name="transaction"), path( "transaction//invoice/", diff --git a/nummi/main/views.py b/nummi/main/views.py index 72806be..9738afd 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -30,7 +30,7 @@ class IndexView(LoginRequiredMixin, TemplateView): "accounts": Account.objects.filter(user=self.request.user), "transactions": Transaction.objects.filter(user=self.request.user)[:10], "categories": Category.objects.filter(user=self.request.user), - "snapshots": Snapshot.objects.filter(user=self.request.user), + "snapshots": Snapshot.objects.filter(user=self.request.user)[:10], } @@ -173,18 +173,35 @@ class SnapshotDeleteView(NummiDeleteView): model = Snapshot -class TransactionListView(UserMixin, ListView): +class NummiListView(UserMixin, ListView): paginate_by = 24 + + +class TransactionListView(NummiListView): model = Transaction template_name = "main/transactions.html" context_object_name = "transactions" -class AccountTListView(TransactionListView): +class SnapshotListView(NummiListView): + model = Snapshot + template_name = "main/snapshots.html" + context_object_name = "snapshots" + + +class AccountMixin: def get_queryset(self): return super().get_queryset().filter(account=self.kwargs.get("pk")) +class AccountTListView(AccountMixin, TransactionListView): + pass + + +class AccountSListView(AccountMixin, SnapshotListView): + pass + + class SnapshotTListView(TransactionListView): def get_queryset(self): return super().get_queryset().filter(snapshot=self.kwargs.get("pk"))