Separate detail and edit view for account

This commit is contained in:
Edgar P. Burkhart 2024-01-04 16:05:38 +01:00
parent 6bd83feafe
commit 218a6aca6f
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
12 changed files with 135 additions and 68 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-02 15:52+0100\n"
"POT-Creation-Date: 2024-01-04 16:04+0100\n"
"PO-Revision-Date: 2023-04-22 15:17+0200\n"
"Last-Translator: Edgar P. Burkhart <traduction@edgarpierre.fr>\n"
"Language-Team: \n"
@ -37,6 +37,22 @@ msgstr "Défaut"
msgid "Accounts"
msgstr "Comptes"
#: .\account\templates\account\account_detail.html:15
msgid "Edit account"
msgstr "Modifier le compte"
#: .\account\templates\account\account_detail.html:17
msgid "Statements"
msgstr "Relevés"
#: .\account\templates\account\account_detail.html:21
msgid "Transactions"
msgstr "Transactions"
#: .\account\templates\account\account_detail.html:26
msgid "History"
msgstr "Historique"
#: .\account\templates\account\account_form.html:5
msgid "Create account"
msgstr "Créer un compte"
@ -44,15 +60,3 @@ msgstr "Créer un compte"
#: .\account\templates\account\account_form.html:8
msgid "New account"
msgstr "Nouveau compte"
#: .\account\templates\account\account_form.html:14
msgid "Statements"
msgstr "Relevés"
#: .\account\templates\account\account_form.html:18
msgid "Transactions"
msgstr "Transactions"
#: .\account\templates\account\account_form.html:23
msgid "History"
msgstr "Historique"

View File

@ -0,0 +1,30 @@
{% extends "main/base.html" %}
{% load main_extras %}
{% load i18n %}
{% block title %}{{ object }} {{ block.super }}{% endblock %}
{% block link %}
{{ block.super }}
{% css "main/css/form.css" %}
{% css "main/css/table.css" %}
{% css "main/css/plot.css" %}
{% endblock %}
{% block body %}
<h2>{{ object.icon|remix }}{{ object }}</h2>
<p>
<a href="{% url "edit_account" object.pk %}">{% translate "Edit account" %}</a>
</p>
<section>
<h3>{% translate "Statements" %}</h3>
{% include "statement/statement_table.html" %}
</section>
<section>
<h3>{% translate "Transactions" %}</h3>
{% include "transaction/transaction_table.html" %}
</section>
{% if history %}
<section>
<h3>{% translate "History" %}</h3>
{% include "history/plot.html" %}
</section>
{% endif %}
{% endblock %}

View File

@ -8,21 +8,3 @@
{% translate "New account" %}
{% endblock %}
{% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %}
{% block tables %}
{% if not form.instance|adding %}
<section>
<h3>{% translate "Statements" %}</h3>
{% include "statement/statement_table.html" %}
</section>
<section>
<h3>{% translate "Transactions" %}</h3>
{% include "transaction/transaction_table.html" %}
</section>
{% if history %}
<section>
<h3>{% translate "History" %}</h3>
{% include "history/plot.html" %}
</section>
{% endif %}
{% endif %}
{% endblock %}

View File

@ -6,7 +6,8 @@ from . import views
urlpatterns = [
path("new", views.AccountCreateView.as_view(), name="new_account"),
path("<account>", views.AccountUpdateView.as_view(), name="account"),
path("<account>", views.AccountDetailView.as_view(), name="account"),
path("<account>/edit", views.AccountUpdateView.as_view(), name="edit_account"),
path(
"<account>/transactions",
views.AccountTListView.as_view(),

View File

@ -1,7 +1,12 @@
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
from history.utils import history
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
from main.views import (
NummiCreateView,
NummiDeleteView,
NummiDetailView,
NummiUpdateView,
)
from statement.views import StatementListView
from transaction.views import TransactionListView
@ -50,6 +55,36 @@ class AccountDeleteView(NummiDeleteView):
pk_url_kwarg = "account"
class AccountDetailView(NummiDetailView):
model = Account
pk_url_kwarg = "account"
def get_context_data(self, **kwargs):
_max = 8
data = super().get_context_data(**kwargs)
account = data.get("object")
_transactions = account.transaction_set.all()
if _transactions.count() > _max:
data["transactions_url"] = reverse_lazy(
"account_transactions", 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_statement_url": reverse_lazy(
"new_statement", kwargs={"account": account.pk}
),
"statements": _statements[:8],
"history": history(account.transaction_set),
}
class AccountMixin:
def get_queryset(self):
self.account = get_object_or_404(

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-03 15:51+0100\n"
"POT-Creation-Date: 2024-01-04 16:04+0100\n"
"PO-Revision-Date: 2023-04-23 08:03+0200\n"
"Last-Translator: Edgar P. Burkhart <traduction@edgarpierre.fr>\n"
"Language-Team: \n"
@ -37,37 +37,21 @@ msgstr "Relevés"
msgid "Transactions"
msgstr "Transactions"
#: .\main\templates\main\base.html:51 .\main\templates\main\index.html:39
msgid "Create account"
msgstr "Créer un compte"
#: .\main\templates\main\base.html:56
msgid "Create statement"
msgstr "Créer un relevé"
#: .\main\templates\main\base.html:61
msgid "Create category"
msgstr "Créer une catégorie"
#: .\main\templates\main\base.html:66
msgid "Create transaction"
msgstr "Créer une transaction"
#: .\main\templates\main\base.html:71 .\main\templates\main\list.html:10
#: .\main\templates\main\base.html:51 .\main\templates\main\list.html:10
#: .\main\templates\main\list.html:34
msgid "Search"
msgstr "Rechercher"
#: .\main\templates\main\base.html:74
#: .\main\templates\main\base.html:54
msgid "Log out"
msgstr "Se déconnecter"
#: .\main\templates\main\base.html:79 .\main\templates\main\form\login.html:6
#: .\main\templates\main\base.html:59 .\main\templates\main\form\login.html:6
#: .\main\templates\main\login.html:11
msgid "Log in"
msgstr "Se connecter"
#: .\main\templates\main\base.html:85
#: .\main\templates\main\base.html:65
#, python-format
msgid "Logged in as <strong>%(user)s</strong>"
msgstr "Connecté en tant que <strong>%(user)s</strong>"
@ -117,22 +101,39 @@ msgstr "Compte"
msgid "Balance"
msgstr "Solde"
#: .\main\templates\main\index.html:32
#: .\main\templates\main\index.html:19 .\main\templates\main\index.html:30
msgid "Edit"
msgstr "Modifier"
#: .\main\templates\main\index.html:34
msgid "No account"
msgstr "Aucun compte"
#: .\main\templates\main\index.html:47
#: .\main\templates\main\index.html:41
msgid "Create account"
msgstr "Créer un compte"
#: .\main\templates\main\index.html:48
msgid "Categories"
msgstr "Catégories"
#: .\main\templates\main\index.html:53
msgid "No category"
msgstr "Aucune catégorie"
#: .\main\templates\main\index.html:54
msgid "Create category"
msgstr "Créer une catégorie"
#: .\main\templates\main\index.html:62
#: .\main\templates\main\index.html:61
msgid "History"
msgstr "Historique"
#: .\main\views.py:68
#: .\main\views.py:69
msgid "was created successfully"
msgstr "a été créé avec succès"
#~ msgid "Create statement"
#~ msgstr "Créer un relevé"
#~ msgid "Create transaction"
#~ msgstr "Créer une transaction"
#~ msgid "No category"
#~ msgstr "Aucune catégorie"

View File

@ -9,6 +9,7 @@ form {
> table > tbody > tr > th {
background: var(--bg-01);
background-clip: padding-box;
border-right: 1px solid var(--gray);
}
tbody :is(input, select, textarea) {
font: inherit;

View File

@ -234,21 +234,25 @@ footer {
&.green,
&.red,
&.white {
color: var(--bg);
&.green {
background: var(--green);
color: var(--bg);
}
&.red {
background: var(--red);
color: var(--bg);
}
&.white {
background: var(--bg-01);
color: var(--text);
}
border-radius: var(--radius);
height: 1.5rem;
width: 1.5rem;
line-height: 1.5rem;
height: 1.5em;
width: 1.5em;
line-height: 1.5em;
}
h2 & {
margin-right: 0.5em;
}
}

View File

@ -16,6 +16,7 @@
<tr>
<th colspan="2">{% translate "Account" %}</th>
<th>{% translate "Balance" %}</th>
<th>{% translate "Edit" %}</th>
</tr>
</thead>
<tbody>
@ -26,16 +27,19 @@
<a href="{{ acc.get_absolute_url }}">{{ acc }}</a>
</th>
<td class="value">{{ acc.statement_set.first.value|value }}</td>
<td>
<a href="{% url "edit_account" acc.pk %}">{% translate "Edit" %}</a>
</td>
</tr>
{% empty %}
<tr>
<td class="empty" colspan="3">{% translate "No account" %}</td>
<td class="empty" colspan="4">{% translate "No account" %}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="new">
<td colspan="3">
<td colspan="4">
<a href="{% url "new_account" %}">{% translate "Create account" %}</a>
</td>
</tr>

View File

@ -9,6 +9,7 @@ from django.utils.translation import gettext as _
from django.views.generic import (
CreateView,
DeleteView,
DetailView,
ListView,
TemplateView,
UpdateView,
@ -76,6 +77,10 @@ class NummiUpdateView(UserMixin, UpdateView):
pass
class NummiDetailView(UserMixin, DetailView):
pass
class NummiDeleteView(UserMixin, DeleteView):
template_name = "main/confirm_delete.html"
success_url = reverse_lazy("index")