Enable archiving accounts

This commit is contained in:
Edgar P. Burkhart 2024-12-29 10:38:25 +01:00
parent 50ae922a99
commit cf25fd1826
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
7 changed files with 42 additions and 1 deletions

View file

@ -10,4 +10,5 @@ class AccountForm(NummiForm):
"name",
"icon",
"default",
"archived",
]

View file

@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2024-12-29 09:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("account", "0002_alter_account_table"),
]
operations = [
migrations.AddField(
model_name="account",
name="archived",
field=models.BooleanField(default=False, verbose_name="Archived"),
),
]

View file

@ -15,6 +15,7 @@ class Account(UserModel):
verbose_name=_("Icon"),
)
default = models.BooleanField(default=False, verbose_name=_("Default"))
archived = models.BooleanField(default=False, verbose_name=_("Archived"))
def save(self, *args, **kwargs):
if self.default:

View file

@ -33,6 +33,9 @@ table {
border-style: dashed;
}
}
&:not(.show-archive) tr.archived {
display: none;
}
td,
th {
padding: 0 var(--gap);

View file

@ -0,0 +1,8 @@
for (let table of document.querySelectorAll("table")) {
let btn = table.querySelector("button.show-archive");
if (btn) {
btn.addEventListener("click", (event) => {
table.classList.toggle("show-archive");
});
}
}

View file

@ -6,6 +6,7 @@
{{ block.super }}
{% css "main/css/table.css" %}
{% css "main/css/plot.css" %}
{% js "main/js/index.js" %}
{% endblock %}
{% block body %}
<div class="split">
@ -22,7 +23,7 @@
</thead>
<tbody>
{% for acc in accounts %}
<tr>
<tr class="{% if acc.archived %}archived{% endif %}">
<td>{{ acc.icon|remix }}</td>
<th class="l">
<a href="{{ acc.get_absolute_url }}">{{ acc }}</a>
@ -52,6 +53,11 @@
<a href="{% url "new_account" %}">{% translate "Create account" %}</a>
</td>
</tr>
<tr>
<td colspan="4">
<button class="show-archive">{% translate "Show archived" %}</button>
</td>
</tr>
</tfoot>
</table>
</div>

View file

@ -61,6 +61,11 @@ def css(href):
)
@register.simple_tag
def js(href):
return mark_safe(f"""<script src="{static(href)}" defer></script>""")
@register.filter
def balance(accounts):
return sum(