From 2736c2ae9dc224d8972c41c639b686201c75ab32 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sat, 22 Apr 2023 12:03:08 +0200 Subject: [PATCH] Implemented frontend for account --- nummi/account/models.py | 4 +-- .../templates/account/account_form.html} | 2 +- nummi/account/urls.py | 20 +++++++------- nummi/account/views.py | 27 +++++++++---------- nummi/category/urls.py | 3 ++- nummi/main/templates/main/base.html | 12 ++++----- .../form/{snapshot.html => statement.html} | 0 nummi/main/templates/main/index.html | 6 ++--- .../list/{snapshot.html => statement.html} | 20 ++++++++++---- .../main/templates/main/list/transaction.html | 14 ++++++++-- .../table/{snapshot.html => statement.html} | 18 ++++++------- .../templates/main/table/transaction.html | 6 ++--- nummi/main/urls.py | 7 ++++- nummi/main/views.py | 5 ++++ nummi/statement/urls.py | 5 ++-- nummi/transaction/forms.py | 2 +- 16 files changed, 92 insertions(+), 59 deletions(-) rename nummi/{main/templates/main/form/account.html => account/templates/account/account_form.html} (92%) rename nummi/main/templates/main/form/{snapshot.html => statement.html} (100%) rename nummi/main/templates/main/list/{snapshot.html => statement.html} (53%) rename nummi/main/templates/main/table/{snapshot.html => statement.html} (76%) diff --git a/nummi/account/models.py b/nummi/account/models.py index 594f5e9..4709ef5 100644 --- a/nummi/account/models.py +++ b/nummi/account/models.py @@ -27,10 +27,10 @@ class Account(UserModel): return str(self.name) def get_absolute_url(self): - return reverse("account", kwargs={"pk": self.pk}) + return reverse("account", args=(self.pk,)) def get_delete_url(self): - return reverse("del_account", kwargs={"pk": self.pk}) + return reverse("del_account", args=(self.pk,)) class Meta: ordering = ["-default", "name"] diff --git a/nummi/main/templates/main/form/account.html b/nummi/account/templates/account/account_form.html similarity index 92% rename from nummi/main/templates/main/form/account.html rename to nummi/account/templates/account/account_form.html index 5d16607..0e18fbb 100644 --- a/nummi/main/templates/main/form/account.html +++ b/nummi/account/templates/account/account_form.html @@ -11,7 +11,7 @@ {% block tables %} {% if not form.instance|adding %}

{% translate "Statements" %}

- {% include "main/table/snapshot.html" %} + {% include "main/table/statement.html" %} {% endif %} {% if transactions %}

{% translate "Transactions" %}

diff --git a/nummi/account/urls.py b/nummi/account/urls.py index b5158ea..43bc302 100644 --- a/nummi/account/urls.py +++ b/nummi/account/urls.py @@ -1,33 +1,35 @@ from django.urls import path +from statement.views import StatementCreateView +from transaction.views import TransactionMonthView from . import views urlpatterns = [ - path("account", views.AccountCreateView.as_view(), name="new_account"), - path("account/", views.AccountUpdateView.as_view(), name="account"), + path("", views.AccountCreateView.as_view(), name="new_account"), + path("", views.AccountUpdateView.as_view(), name="account"), path( - "account//transactions", + "/transactions", views.AccountTListView.as_view(), name="account_transactions", ), path( - "account//statements", + "/statements", views.AccountSListView.as_view(), name="account_statements", ), path( - "account//statement", - views.StatementCreateView.as_view(), + "/statement", + StatementCreateView.as_view(), name="new_statement", ), path( - "account//delete", + "/delete", views.AccountDeleteView.as_view(), name="del_account", ), path( - "account//history//", - views.TransactionMonthView.as_view(), + "/history//", + TransactionMonthView.as_view(), name="transaction_month", ), ] diff --git a/nummi/account/views.py b/nummi/account/views.py index 576d153..62fd3ac 100644 --- a/nummi/account/views.py +++ b/nummi/account/views.py @@ -1,6 +1,6 @@ from django.urls import reverse_lazy from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView -from snapshot.views import SnapshotListView +from statement.views import StatementListView from transaction.utils import history from transaction.views import TransactionListView @@ -11,13 +11,12 @@ from .models import Account class AccountCreateView(NummiCreateView): model = Account form_class = AccountForm - template_name = "main/form/account.html" class AccountUpdateView(NummiUpdateView): model = Account form_class = AccountForm - template_name = "main/form/account.html" + pk_url_kwarg = "account" def get_context_data(self, **kwargs): _max = 8 @@ -29,34 +28,34 @@ class AccountUpdateView(NummiUpdateView): data["transactions_url"] = reverse_lazy( "account_transactions", args=(account.pk,) ) - _snapshots = account.snapshot_set.all() - if _snapshots.count() > _max: - data["snapshots_url"] = reverse_lazy( - "account_snapshots", args=(account.pk,) + _statements = account.statement_set.all() + if _statements.count() > _max: + data["statements_url"] = reverse_lazy( + "account_statements", args=(account.pk,) ) return data | { "transactions": _transactions[:8], - "new_snapshot_url": reverse_lazy( - "new_snapshot", kwargs={"account": account.pk} + "new_statement_url": reverse_lazy( + "new_statement", kwargs={"account": account.pk} ), - "snapshots": _snapshots[:8], + "statements": _statements[:8], "history": history(account.transaction_set), } class AccountDeleteView(NummiDeleteView): model = Account + pk_url_kwarg = "account" class AccountMixin: def get_queryset(self): - return super().get_queryset().filter(account=self.kwargs.get("pk")) + return super().get_queryset().filter(account=self.kwargs.get("account")) def get_context_data(self, **kwargs): return super().get_context_data(**kwargs) | { - "object": Account.objects.get(pk=self.kwargs.get("pk")), - "account": True, + "account": Account.objects.get(pk=self.kwargs.get("account")), } @@ -64,5 +63,5 @@ class AccountTListView(AccountMixin, TransactionListView): pass -class AccountSListView(AccountMixin, SnapshotListView): +class AccountSListView(AccountMixin, StatementListView): pass diff --git a/nummi/category/urls.py b/nummi/category/urls.py index 113aac9..601e925 100644 --- a/nummi/category/urls.py +++ b/nummi/category/urls.py @@ -1,4 +1,5 @@ from django.urls import path +from transaction.views import TransactionMonthView from . import views @@ -15,7 +16,7 @@ urlpatterns = [ ), path( "category//history//", - views.TransactionMonthView.as_view(), + TransactionMonthView.as_view(), name="transaction_month", ), ] diff --git a/nummi/main/templates/main/base.html b/nummi/main/templates/main/base.html index c58e059..274bfd4 100644 --- a/nummi/main/templates/main/base.html +++ b/nummi/main/templates/main/base.html @@ -33,9 +33,9 @@ accesskey="h">{% translate "Home" %}
  • - - {% translate "Snapshots" %} + + {% translate "Statements" %}
  • @@ -50,9 +50,9 @@ accesskey="a">{% translate "Create account" %}
  • - {% translate "Create snapshot" %} + {% translate "Create statement" %}
  • {% endspaceless %} {% endif %} - {% if snapshots %} -

    {% translate "Snapshots" %}

    - {% include "main/table/snapshot.html" %} + {% if statements %} +

    {% translate "Statements" %}

    + {% include "main/table/statement.html" %} {% endif %} {% if history.data %}

    {% translate "History" %}

    diff --git a/nummi/main/templates/main/list/snapshot.html b/nummi/main/templates/main/list/statement.html similarity index 53% rename from nummi/main/templates/main/list/snapshot.html rename to nummi/main/templates/main/list/statement.html index b7ce44a..f6b31a9 100644 --- a/nummi/main/templates/main/list/snapshot.html +++ b/nummi/main/templates/main/list/statement.html @@ -4,7 +4,8 @@ {% load i18n %} {% block title %} {% translate "Statements" %} - {% if object %}– {{ object }}{% endif %} + {% if account %}– {{ account }}{% endif %} + {% if category %}– {{ category }}{% endif %} – Nummi {% endblock %} {% block link %} @@ -18,12 +19,21 @@ {% endblock %} {% block body %}

    {% translate "Statements" %}

    - {% if object %}
    {{ object }}{% endif %} - {% if snapshots %} + {% if account %} +

    + {{ account.icon|remix }}{{ account }} +

    + {% endif %} + {% if category %} +

    + {{ category.icon|remix }}{{ category }} +

    + {% endif %} + {% if statements %} {% include "main/list/pagination.html" %} - {% include "main/table/snapshot.html" %} + {% include "main/table/statement.html" %} {% include "main/list/pagination.html" %} {% else %} -

    {% translate "No snapshots to show" %}

    +

    {% translate "No statements to show" %}

    {% endif %} {% endblock %} diff --git a/nummi/main/templates/main/list/transaction.html b/nummi/main/templates/main/list/transaction.html index 70a0c2e..de2f7b0 100644 --- a/nummi/main/templates/main/list/transaction.html +++ b/nummi/main/templates/main/list/transaction.html @@ -4,7 +4,8 @@ {% load i18n %} {% block title %} {% translate "Transactions" %} - {% if object %}– {{ object }}{% endif %} + {% if account %}– {{ account }}{% endif %} + {% if category %}– {{ category }}{% endif %} {% if search %} – {% translate "Search" %} {% endif %} @@ -21,7 +22,16 @@ {% endblock %} {% block body %}

    {% translate "Transactions" %}

    - {% if object %}{{ object }}{% endif %} + {% if account %} +

    + {{ account.icon|remix }}{{ account }} +

    + {% endif %} + {% if category %} +

    + {{ category.icon|remix }}{{ category }} +

    + {% endif %} {% if search %} {% translate "Search" %} {% endif %} diff --git a/nummi/main/templates/main/table/snapshot.html b/nummi/main/templates/main/table/statement.html similarity index 76% rename from nummi/main/templates/main/table/snapshot.html rename to nummi/main/templates/main/table/statement.html index 23cc6d5..ebe81b7 100644 --- a/nummi/main/templates/main/table/snapshot.html +++ b/nummi/main/templates/main/table/statement.html @@ -1,12 +1,12 @@ {% load main_extras %} {% load i18n %} -{% if new_snapshot_url %} +{% if new_statement_url %}

    - {% translate "Create statement" %} + {% translate "Create statement" %}

    {% endif %} -
    - +
    +
    @@ -28,7 +28,7 @@ - {% for snap in snapshots %} + {% for snap in statements %} {% if snap.sum == snap.diff %} @@ -39,12 +39,12 @@ {% if snap.file %}{{ "attachment"|remix }}{% endif %} {% if not account %} {% endif %} @@ -55,8 +55,8 @@
    {% translate "Transactions" %}
    {{ "check"|remix }} - {{ snap.date|date:"Y-m-d" }} + {{ snap.date|date:"Y-m-d" }} {{ snap.account.icon|remix }} - {{ snap.account }} + {{ snap.account }} {{ snap.value|value }}
    -{% if snapshots_url %} +{% if statements_url %}

    - {% translate "View all statements" %} + {% translate "View all statements" %}

    {% endif %} diff --git a/nummi/main/templates/main/table/transaction.html b/nummi/main/templates/main/table/transaction.html index da11aa8..fe7c34b 100644 --- a/nummi/main/templates/main/table/transaction.html +++ b/nummi/main/templates/main/table/transaction.html @@ -43,7 +43,7 @@ {{ trans.date|date:"Y-m-d" }} - {{ trans.name }} + {{ trans.name }} {{ trans.value|pmvalue }} {{ trans.trader|default_if_none:"" }} @@ -51,7 +51,7 @@ {% if trans.category %} {{ trans.category.icon|remix }} - {{ trans.category }} + {{ trans.category }} {% else %} @@ -60,7 +60,7 @@ {% if not account %} {{ trans.account.icon|remix }} - {{ trans.account }} + {{ trans.account }} {% endif %} diff --git a/nummi/main/urls.py b/nummi/main/urls.py index 3b911ad..0b5893d 100644 --- a/nummi/main/urls.py +++ b/nummi/main/urls.py @@ -1,4 +1,4 @@ -from django.urls import path +from django.urls import include, path from . import views @@ -6,4 +6,9 @@ urlpatterns = [ path("", views.IndexView.as_view(), name="index"), path("login", views.LoginView.as_view(), name="login"), path("logout", views.LogoutView.as_view(), name="logout"), + path("account/", include("account.urls")), + path("category/", include("category.urls")), + path("statement/", include("statement.urls")), + path("transaction/", include("transaction.urls")), + path("search/", include("search.urls")), ] diff --git a/nummi/main/views.py b/nummi/main/views.py index 7ede354..e7fbea9 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -66,6 +66,11 @@ class NummiDeleteView(UserMixin, DeleteView): template_name = "main/confirm_delete.html" success_url = reverse_lazy("index") + def get_form_kwargs(self): + _res = super().get_form_kwargs() + _res.pop("user") + return _res + class LoginView(auth_views.LoginView): template_name = "main/login.html" diff --git a/nummi/statement/urls.py b/nummi/statement/urls.py index 65ac4ec..c5d7442 100644 --- a/nummi/statement/urls.py +++ b/nummi/statement/urls.py @@ -1,9 +1,10 @@ from django.urls import path +from transaction.views import TransactionCreateView from . import views urlpatterns = [ - path("statements", views.SnapshotListView.as_view(), name="statements"), + path("statements", views.StatementListView.as_view(), name="statements"), path("statement", views.StatementCreateView.as_view(), name="new_statement"), path("statement/", views.StatementUpdateView.as_view(), name="statement"), path( @@ -13,7 +14,7 @@ urlpatterns = [ ), path( "statement//transaction", - views.TransactionCreateView.as_view(), + TransactionCreateView.as_view(), name="new_transaction", ), path( diff --git a/nummi/transaction/forms.py b/nummi/transaction/forms.py index f492e21..0d661e0 100644 --- a/nummi/transaction/forms.py +++ b/nummi/transaction/forms.py @@ -1,6 +1,6 @@ from category.models import Category from main.forms import NummiFileInput, NummiForm -from Statement.models import Statement +from statement.models import Statement from .models import Invoice, Transaction