Create account list view

This commit is contained in:
Edgar P. Burkhart 2025-01-02 10:07:01 +01:00
parent 8575f43475
commit 57d5330d75
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
12 changed files with 105 additions and 59 deletions

View file

@ -0,0 +1,17 @@
{% extends "main/list.html" %}
{% load i18n main_extras account_extras %}
{% block link %}
{{ block.super }}
{% css "main/css/table.css" %}
{% css "main/css/plot.css" %}
{% js "main/js/index.js" %}
{% endblock link %}
{% block name %}
{% translate "Account" %}
{% endblock name %}
{% block h2 %}
{% translate "Accounts" %}
{% endblock h2 %}
{% block table %}
<div class="split">{% account_table accounts %}</div>
{% endblock table %}

View file

@ -0,0 +1,41 @@
{% load i18n main_extras %}
<dl class="accounts">
{% for acc in accounts %}
<div class="account {% if acc.archived %}archived{% endif %}">
<dt>
<a href="{{ acc.get_absolute_url }}">{{ acc.icon|remix }}{{ acc }}</a>
</dt>
<dd class="value">
{% if acc.statement_set.first %}{{ acc.statement_set.first.value|value }}{% endif %}
</dd>
</div>
{% endfor %}
{% if index %}
<div class="more account">
<dt>
<a href="{% url "accounts" %}">{{ "gallery-view"|remixnl }}{% translate "All accounts" %}</a>
</dt>
{% if total %}
<dd class="value">
{{ total|value }}
</dd>
{% endif %}
</div>
{% else %}
<div class="more account">
<dt>
<label class="wi" for="show-archived-accounts">
{{ "archive"|remix }}{% translate "Show archived" %}
</label>
</dt>
<dd>
<input type="checkbox" class="show-archived" id="show-archived-accounts" />
</dd>
</div>
<div class="new account">
<dt>
<a href="{% url "new_account" %}">{{ "add-box"|remix }}{% translate "Create account" %}</a>
</dt>
</div>
{% endif %}
</dl>

View file

View file

@ -0,0 +1,10 @@
from django import template
register = template.Library()
@register.inclusion_tag("account/account_table.html")
def account_table(accounts, **kwargs):
return kwargs | {
"accounts": accounts,
}

View file

@ -5,6 +5,7 @@ from transaction.views import TransactionMonthView, TransactionYearView
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("list", views.AccountListView.as_view(), name="accounts"),
path("new", views.AccountCreateView.as_view(), name="new_account"), path("new", views.AccountCreateView.as_view(), name="new_account"),
path("<account>", views.AccountDetailView.as_view(), name="account"), path("<account>", views.AccountDetailView.as_view(), name="account"),
path("<account>/edit", views.AccountUpdateView.as_view(), name="edit_account"), path("<account>/edit", views.AccountUpdateView.as_view(), name="edit_account"),

View file

@ -5,6 +5,7 @@ from main.views import (
NummiCreateView, NummiCreateView,
NummiDeleteView, NummiDeleteView,
NummiDetailView, NummiDetailView,
NummiListView,
NummiUpdateView, NummiUpdateView,
) )
from statement.views import StatementListView from statement.views import StatementListView
@ -66,6 +67,11 @@ class AccountMixin:
return super().get_context_data(**kwargs) | {"account": self.account} return super().get_context_data(**kwargs) | {"account": self.account}
class AccountListView(NummiListView):
model = Account
context_object_name = "accounts"
class AccountTListView(AccountMixin, TransactionListView): class AccountTListView(AccountMixin, TransactionListView):
pass pass

View file

@ -336,12 +336,9 @@ ul.messages {
} }
} }
.accounts { dl.accounts {
display: grid;
grid-auto-rows: min-content;
dl {
margin: 0; margin: 0;
dt, dt,
dd { dd {
margin: 0; margin: 0;
@ -364,7 +361,6 @@ ul.messages {
&:not(.show-archive) .account.archived { &:not(.show-archive) .account.archived {
display: none; display: none;
} }
}
} }
ul.statements, ul.statements,

View file

@ -1,10 +1,9 @@
let accounts = document.querySelector(".accounts"); let accounts = document.querySelector("dl.accounts");
let toggle = accounts.querySelector("input#show-archived-accounts"); let toggle = accounts.querySelector("input#show-archived-accounts");
let dl = accounts.querySelector("dl");
dl.classList.toggle("show-archive", toggle.checked); accounts.classList.toggle("show-archive", toggle.checked);
if (toggle) { if (toggle) {
toggle.addEventListener("change", (event) => { toggle.addEventListener("change", (event) => {
dl.classList.toggle("show-archive", toggle.checked); accounts.classList.toggle("show-archive", toggle.checked);
}); });
} }

View file

@ -1,6 +1,6 @@
{% extends "main/base.html" %} {% extends "main/base.html" %}
{% load static %} {% load static %}
{% load main_extras %} {% load main_extras account_extras %}
{% load i18n %} {% load i18n %}
{% block link %} {% block link %}
{{ block.super }} {{ block.super }}
@ -10,42 +10,16 @@
{% endblock link %} {% endblock link %}
{% block body %} {% block body %}
<div class="split"> <div class="split">
<section class="accounts"> <section>
<h2>{% translate "Accounts" %}</h2> <h2>{% translate "Accounts" %}</h2>
<dl> {% account_table accounts index=True total=accounts|balance %}
{% for acc in accounts %}
<div class="account {% if acc.archived %}archived{% endif %}">
<dt>
<a href="{{ acc.get_absolute_url }}">{{ acc.icon|remix }}{{ acc }}</a>
</dt>
<dd>
{% if acc.statement_set.first %}{{ acc.statement_set.first.value|value }}{% endif %}
</dd>
</div>
{% endfor %}
<div class="more account">
<dt>
<label class="wi" for="show-archived-accounts">
{{ "archive"|remix }}{% translate "Show archived" %}
</label>
</dt>
<dd>
<input type="checkbox" class="show-archived" id="show-archived-accounts" />
</dd>
</div>
<div class="new account">
<dt>
<a href="{% url "new_account" %}">{{ "add-box"|remix }}{% translate "Create account" %}</a>
</dt>
</div>
</dl>
</section> </section>
<section class="statements"> <section>
<h2>{% translate "Statements" %}</h2> <h2>{% translate "Statements" %}</h2>
{% include "statement/statement_table.html" %} {% include "statement/statement_table.html" %}
</section> </section>
</div> </div>
<section class="categories"> <section>
<h2>{% translate "Categories" %}</h2> <h2>{% translate "Categories" %}</h2>
{% spaceless %} {% spaceless %}
<p> <p>

View file

@ -105,4 +105,4 @@ class LogoutView(auth_views.LogoutView):
class NummiListView(UserMixin, ListView): class NummiListView(UserMixin, ListView):
paginate_by = 96 pass

View file

@ -84,6 +84,7 @@ class StatementDetailView(NummiDetailView):
class StatementListView(NummiListView): class StatementListView(NummiListView):
model = Statement model = Statement
context_object_name = "statements" context_object_name = "statements"
paginate_by = 32
class StatementMixin: class StatementMixin:

View file

@ -124,6 +124,7 @@ class InvoiceDeleteView(NummiDeleteView):
class TransactionListView(NummiListView): class TransactionListView(NummiListView):
model = Transaction model = Transaction
context_object_name = "transactions" context_object_name = "transactions"
paginate_by = 50
class TransactionACMixin: class TransactionACMixin: