Implemented frontend for account
This commit is contained in:
parent
bb4a8c5db1
commit
719436f9ad
16 changed files with 97 additions and 61 deletions
|
@ -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"]
|
||||
|
|
22
nummi/account/templates/account/account_form.html
Normal file
22
nummi/account/templates/account/account_form.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
{% extends "main/form/base.html" %}
|
||||
{% load main_extras %}
|
||||
{% load i18n %}
|
||||
{% block title_new %}
|
||||
{% translate "Create account" %}
|
||||
{% endblock %}
|
||||
{% block h2_new %}
|
||||
{% translate "New account" %}
|
||||
{% endblock %}
|
||||
{% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %}
|
||||
{% block tables %}
|
||||
{% if not form.instance|adding %}
|
||||
<h3>{% translate "Statements" %}</h3>
|
||||
{% include "main/table/statement.html" %}
|
||||
{% endif %}
|
||||
{% if transactions %}
|
||||
<h3>{% translate "Transactions" %}</h3>
|
||||
{% include "main/table/transaction.html" %}
|
||||
<h3>{% translate "History" %}</h3>
|
||||
{% include "main/plot/history.html" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -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/<pk>", views.AccountUpdateView.as_view(), name="account"),
|
||||
path("", views.AccountCreateView.as_view(), name="new_account"),
|
||||
path("<account>", views.AccountUpdateView.as_view(), name="account"),
|
||||
path(
|
||||
"account/<pk>/transactions",
|
||||
"<account>/transactions",
|
||||
views.AccountTListView.as_view(),
|
||||
name="account_transactions",
|
||||
),
|
||||
path(
|
||||
"account/<pk>/statements",
|
||||
"<account>/statements",
|
||||
views.AccountSListView.as_view(),
|
||||
name="account_statements",
|
||||
),
|
||||
path(
|
||||
"account/<account>/statement",
|
||||
views.StatementCreateView.as_view(),
|
||||
"<account>/statement",
|
||||
StatementCreateView.as_view(),
|
||||
name="new_statement",
|
||||
),
|
||||
path(
|
||||
"account/<pk>/delete",
|
||||
"<account>/delete",
|
||||
views.AccountDeleteView.as_view(),
|
||||
name="del_account",
|
||||
),
|
||||
path(
|
||||
"account/<account>/history/<int:year>/<int:month>",
|
||||
views.TransactionMonthView.as_view(),
|
||||
"<account>/history/<int:year>/<int:month>",
|
||||
TransactionMonthView.as_view(),
|
||||
name="transaction_month",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
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 +12,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,40 +29,42 @@ 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"))
|
||||
self.account = get_object_or_404(
|
||||
Account.objects.filter(user=self.request.user),
|
||||
pk=self.kwargs.get("account"),
|
||||
)
|
||||
return super().get_queryset().filter(account=self.account)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"object": Account.objects.get(pk=self.kwargs.get("pk")),
|
||||
"account": True,
|
||||
}
|
||||
return super().get_context_data(**kwargs) | {"account": self.account}
|
||||
|
||||
|
||||
class AccountTListView(AccountMixin, TransactionListView):
|
||||
pass
|
||||
|
||||
|
||||
class AccountSListView(AccountMixin, SnapshotListView):
|
||||
class AccountSListView(AccountMixin, StatementListView):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue