Implemented frontend for account

This commit is contained in:
Edgar P. Burkhart 2023-04-22 12:03:08 +02:00
parent bb4a8c5db1
commit 2736c2ae9d
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
16 changed files with 92 additions and 59 deletions

View file

@ -27,10 +27,10 @@ class Account(UserModel):
return str(self.name) return str(self.name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse("account", kwargs={"pk": self.pk}) return reverse("account", args=(self.pk,))
def get_delete_url(self): def get_delete_url(self):
return reverse("del_account", kwargs={"pk": self.pk}) return reverse("del_account", args=(self.pk,))
class Meta: class Meta:
ordering = ["-default", "name"] ordering = ["-default", "name"]

View file

@ -11,7 +11,7 @@
{% block tables %} {% block tables %}
{% if not form.instance|adding %} {% if not form.instance|adding %}
<h3>{% translate "Statements" %}</h3> <h3>{% translate "Statements" %}</h3>
{% include "main/table/snapshot.html" %} {% include "main/table/statement.html" %}
{% endif %} {% endif %}
{% if transactions %} {% if transactions %}
<h3>{% translate "Transactions" %}</h3> <h3>{% translate "Transactions" %}</h3>

View file

@ -1,33 +1,35 @@
from django.urls import path from django.urls import path
from statement.views import StatementCreateView
from transaction.views import TransactionMonthView
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("account", views.AccountCreateView.as_view(), name="new_account"), path("", views.AccountCreateView.as_view(), name="new_account"),
path("account/<pk>", views.AccountUpdateView.as_view(), name="account"), path("<account>", views.AccountUpdateView.as_view(), name="account"),
path( path(
"account/<pk>/transactions", "<account>/transactions",
views.AccountTListView.as_view(), views.AccountTListView.as_view(),
name="account_transactions", name="account_transactions",
), ),
path( path(
"account/<pk>/statements", "<account>/statements",
views.AccountSListView.as_view(), views.AccountSListView.as_view(),
name="account_statements", name="account_statements",
), ),
path( path(
"account/<account>/statement", "<account>/statement",
views.StatementCreateView.as_view(), StatementCreateView.as_view(),
name="new_statement", name="new_statement",
), ),
path( path(
"account/<pk>/delete", "<account>/delete",
views.AccountDeleteView.as_view(), views.AccountDeleteView.as_view(),
name="del_account", name="del_account",
), ),
path( path(
"account/<account>/history/<int:year>/<int:month>", "<account>/history/<int:year>/<int:month>",
views.TransactionMonthView.as_view(), TransactionMonthView.as_view(),
name="transaction_month", name="transaction_month",
), ),
] ]

View file

@ -1,6 +1,6 @@
from django.urls import reverse_lazy from django.urls import reverse_lazy
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
from snapshot.views import SnapshotListView from statement.views import StatementListView
from transaction.utils import history from transaction.utils import history
from transaction.views import TransactionListView from transaction.views import TransactionListView
@ -11,13 +11,12 @@ from .models import Account
class AccountCreateView(NummiCreateView): class AccountCreateView(NummiCreateView):
model = Account model = Account
form_class = AccountForm form_class = AccountForm
template_name = "main/form/account.html"
class AccountUpdateView(NummiUpdateView): class AccountUpdateView(NummiUpdateView):
model = Account model = Account
form_class = AccountForm form_class = AccountForm
template_name = "main/form/account.html" pk_url_kwarg = "account"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
_max = 8 _max = 8
@ -29,34 +28,34 @@ class AccountUpdateView(NummiUpdateView):
data["transactions_url"] = reverse_lazy( data["transactions_url"] = reverse_lazy(
"account_transactions", args=(account.pk,) "account_transactions", args=(account.pk,)
) )
_snapshots = account.snapshot_set.all() _statements = account.statement_set.all()
if _snapshots.count() > _max: if _statements.count() > _max:
data["snapshots_url"] = reverse_lazy( data["statements_url"] = reverse_lazy(
"account_snapshots", args=(account.pk,) "account_statements", args=(account.pk,)
) )
return data | { return data | {
"transactions": _transactions[:8], "transactions": _transactions[:8],
"new_snapshot_url": reverse_lazy( "new_statement_url": reverse_lazy(
"new_snapshot", kwargs={"account": account.pk} "new_statement", kwargs={"account": account.pk}
), ),
"snapshots": _snapshots[:8], "statements": _statements[:8],
"history": history(account.transaction_set), "history": history(account.transaction_set),
} }
class AccountDeleteView(NummiDeleteView): class AccountDeleteView(NummiDeleteView):
model = Account model = Account
pk_url_kwarg = "account"
class AccountMixin: class AccountMixin:
def get_queryset(self): 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): def get_context_data(self, **kwargs):
return super().get_context_data(**kwargs) | { return super().get_context_data(**kwargs) | {
"object": Account.objects.get(pk=self.kwargs.get("pk")), "account": Account.objects.get(pk=self.kwargs.get("account")),
"account": True,
} }
@ -64,5 +63,5 @@ class AccountTListView(AccountMixin, TransactionListView):
pass pass
class AccountSListView(AccountMixin, SnapshotListView): class AccountSListView(AccountMixin, StatementListView):
pass pass

View file

@ -1,4 +1,5 @@
from django.urls import path from django.urls import path
from transaction.views import TransactionMonthView
from . import views from . import views
@ -15,7 +16,7 @@ urlpatterns = [
), ),
path( path(
"category/<category>/history/<int:year>/<int:month>", "category/<category>/history/<int:year>/<int:month>",
views.TransactionMonthView.as_view(), TransactionMonthView.as_view(),
name="transaction_month", name="transaction_month",
), ),
] ]

View file

@ -33,9 +33,9 @@
accesskey="h">{% translate "Home" %}</a> accesskey="h">{% translate "Home" %}</a>
</li> </li>
<li> <li>
<a href="{% url "snapshots" %}" <a href="{% url "statements" %}"
class="{% if request.resolver_match.url_name == "snapshots" %}cur{% endif %}"> class="{% if request.resolver_match.url_name == "statements" %}cur{% endif %}">
{% translate "Snapshots" %} {% translate "Statements" %}
</a> </a>
</li> </li>
<li> <li>
@ -50,9 +50,9 @@
accesskey="a">{% translate "Create account" %}</a> accesskey="a">{% translate "Create account" %}</a>
</li> </li>
<li> <li>
<a href="{% url "new_snapshot" %}" <a href="{% url "new_statement" %}"
class="{% if request.resolver_match.url_name == "new_snapshot" %}cur{% endif %}" class="{% if request.resolver_match.url_name == "new_statement" %}cur{% endif %}"
accesskey="s">{% translate "Create snapshot" %}</a> accesskey="s">{% translate "Create statement" %}</a>
</li> </li>
<li> <li>
<a href="{% url "new_category" %}" <a href="{% url "new_category" %}"

View file

@ -36,9 +36,9 @@
</p> </p>
{% endspaceless %} {% endspaceless %}
{% endif %} {% endif %}
{% if snapshots %} {% if statements %}
<h2>{% translate "Snapshots" %}</h2> <h2>{% translate "Statements" %}</h2>
{% include "main/table/snapshot.html" %} {% include "main/table/statement.html" %}
{% endif %} {% endif %}
{% if history.data %} {% if history.data %}
<h2>{% translate "History" %}</h2> <h2>{% translate "History" %}</h2>

View file

@ -4,7 +4,8 @@
{% load i18n %} {% load i18n %}
{% block title %} {% block title %}
{% translate "Statements" %} {% translate "Statements" %}
{% if object %} {{ object }}{% endif %} {% if account %} {{ account }}{% endif %}
{% if category %} {{ category }}{% endif %}
Nummi Nummi
{% endblock %} {% endblock %}
{% block link %} {% block link %}
@ -18,12 +19,21 @@
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<h2>{% translate "Statements" %}</h2> <h2>{% translate "Statements" %}</h2>
{% if object %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% endif %} {% if account %}
{% if snapshots %} <p>
<a href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
</p>
{% endif %}
{% if category %}
<p>
<a href="{{ category.get_absolute_url }}">{{ category.icon|remix }}{{ category }}</a>
</p>
{% endif %}
{% if statements %}
{% include "main/list/pagination.html" %} {% include "main/list/pagination.html" %}
{% include "main/table/snapshot.html" %} {% include "main/table/statement.html" %}
{% include "main/list/pagination.html" %} {% include "main/list/pagination.html" %}
{% else %} {% else %}
<p>{% translate "No snapshots to show" %}</p> <p>{% translate "No statements to show" %}</p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -4,7 +4,8 @@
{% load i18n %} {% load i18n %}
{% block title %} {% block title %}
{% translate "Transactions" %} {% translate "Transactions" %}
{% if object %} {{ object }}{% endif %} {% if account %} {{ account }}{% endif %}
{% if category %} {{ category }}{% endif %}
{% if search %} {% if search %}
{% translate "Search" %} {% translate "Search" %}
{% endif %} {% endif %}
@ -21,7 +22,16 @@
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<h2>{% translate "Transactions" %}</h2> <h2>{% translate "Transactions" %}</h2>
{% if object %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% endif %} {% if account %}
<p>
<a href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
</p>
{% endif %}
{% if category %}
<p>
<a href="{{ category.get_absolute_url }}">{{ category.icon|remix }}{{ category }}</a>
</p>
{% endif %}
{% if search %} {% if search %}
<a href="{% url "search" %}">{% translate "Search" %}</a> <a href="{% url "search" %}">{% translate "Search" %}</a>
{% endif %} {% endif %}

View file

@ -1,12 +1,12 @@
{% load main_extras %} {% load main_extras %}
{% load i18n %} {% load i18n %}
{% if new_snapshot_url %} {% if new_statement_url %}
<p> <p>
<a href="{{ new_snapshot_url }}">{% translate "Create statement" %}</a> <a href="{{ new_statement_url }}">{% translate "Create statement" %}</a>
</p> </p>
{% endif %} {% endif %}
<div id="snapshots" class="table"> <div id="statements" class="table">
<table class="full-width {% if snapshots_url %}more{% endif %}"> <table class="full-width {% if statements_url %}more{% endif %}">
<colgroup> <colgroup>
<col class="icon" span="2"> <col class="icon" span="2">
<col class="date"> <col class="date">
@ -28,7 +28,7 @@
<th>{% translate "Transactions" %}</th> <th>{% translate "Transactions" %}</th>
</thead> </thead>
<tbody> <tbody>
{% for snap in snapshots %} {% for snap in statements %}
<tr> <tr>
{% if snap.sum == snap.diff %} {% if snap.sum == snap.diff %}
<td class="c green">{{ "check"|remix }}</td> <td class="c green">{{ "check"|remix }}</td>
@ -39,12 +39,12 @@
{% if snap.file %}<a href="{{ snap.file.url }}">{{ "attachment"|remix }}</a>{% endif %} {% if snap.file %}<a href="{{ snap.file.url }}">{{ "attachment"|remix }}</a>{% endif %}
</td> </td>
<th class="date" scope="row"> <th class="date" scope="row">
<a href="{% url "snapshot" pk=snap.id %}">{{ snap.date|date:"Y-m-d" }}</a> <a href="{% url "statement" snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
</th> </th>
{% if not account %} {% if not account %}
<td class="r">{{ snap.account.icon|remix }}</td> <td class="r">{{ snap.account.icon|remix }}</td>
<td> <td>
<a href="{% url "account" pk=snap.account.id %}">{{ snap.account }}</a> <a href="{% url "account" snap.account.id %}">{{ snap.account }}</a>
</td> </td>
{% endif %} {% endif %}
<td class="value">{{ snap.value|value }}</td> <td class="value">{{ snap.value|value }}</td>
@ -55,8 +55,8 @@
</tbody> </tbody>
</table> </table>
</div> </div>
{% if snapshots_url %} {% if statements_url %}
<p> <p>
<a href="{{ snapshots_url }}">{% translate "View all statements" %}</a> <a href="{{ statements_url }}">{% translate "View all statements" %}</a>
</p> </p>
{% endif %} {% endif %}

View file

@ -43,7 +43,7 @@
</td> </td>
<td class="date">{{ trans.date|date:"Y-m-d" }}</td> <td class="date">{{ trans.date|date:"Y-m-d" }}</td>
<th scope="row" class="l"> <th scope="row" class="l">
<a href="{% url "transaction" pk=trans.id %}">{{ trans.name }}</a> <a href="{% url "transaction" trans.id %}">{{ trans.name }}</a>
</th> </th>
<td class="value">{{ trans.value|pmvalue }}</td> <td class="value">{{ trans.value|pmvalue }}</td>
<td>{{ trans.trader|default_if_none:"" }}</td> <td>{{ trans.trader|default_if_none:"" }}</td>
@ -51,7 +51,7 @@
{% if trans.category %} {% if trans.category %}
<td class="r">{{ trans.category.icon|remix }}</td> <td class="r">{{ trans.category.icon|remix }}</td>
<td> <td>
<a href="{% url "category" pk=trans.category.id %}">{{ trans.category }}</a> <a href="{% url "category" trans.category.id %}">{{ trans.category }}</a>
</td> </td>
{% else %} {% else %}
<td colspan="2"></td> <td colspan="2"></td>
@ -60,7 +60,7 @@
{% if not account %} {% if not account %}
<td class="r">{{ trans.account.icon|remix }}</td> <td class="r">{{ trans.account.icon|remix }}</td>
<td> <td>
<a href="{% url "account" pk=trans.account.id %}">{{ trans.account }}</a> <a href="{% url "account" trans.account.id %}">{{ trans.account }}</a>
</td> </td>
{% endif %} {% endif %}
</tr> </tr>

View file

@ -1,4 +1,4 @@
from django.urls import path from django.urls import include, path
from . import views from . import views
@ -6,4 +6,9 @@ urlpatterns = [
path("", views.IndexView.as_view(), name="index"), path("", views.IndexView.as_view(), name="index"),
path("login", views.LoginView.as_view(), name="login"), path("login", views.LoginView.as_view(), name="login"),
path("logout", views.LogoutView.as_view(), name="logout"), 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")),
] ]

View file

@ -66,6 +66,11 @@ class NummiDeleteView(UserMixin, DeleteView):
template_name = "main/confirm_delete.html" template_name = "main/confirm_delete.html"
success_url = reverse_lazy("index") 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): class LoginView(auth_views.LoginView):
template_name = "main/login.html" template_name = "main/login.html"

View file

@ -1,9 +1,10 @@
from django.urls import path from django.urls import path
from transaction.views import TransactionCreateView
from . import views from . import views
urlpatterns = [ 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.StatementCreateView.as_view(), name="new_statement"),
path("statement/<pk>", views.StatementUpdateView.as_view(), name="statement"), path("statement/<pk>", views.StatementUpdateView.as_view(), name="statement"),
path( path(
@ -13,7 +14,7 @@ urlpatterns = [
), ),
path( path(
"statement/<statement>/transaction", "statement/<statement>/transaction",
views.TransactionCreateView.as_view(), TransactionCreateView.as_view(),
name="new_transaction", name="new_transaction",
), ),
path( path(

View file

@ -1,6 +1,6 @@
from category.models import Category from category.models import Category
from main.forms import NummiFileInput, NummiForm from main.forms import NummiFileInput, NummiForm
from Statement.models import Statement from statement.models import Statement
from .models import Invoice, Transaction from .models import Invoice, Transaction