Use templatetag for history_plot

This commit is contained in:
Edgar P. Burkhart 2025-01-02 15:03:10 +01:00
parent b1fddd0dd6
commit 229033aac0
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
8 changed files with 49 additions and 57 deletions

View file

@ -1,5 +1,6 @@
from uuid import uuid4
from django.apps import apps
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
@ -33,6 +34,12 @@ class Account(UserModel):
def get_delete_url(self):
return reverse("del_account", args=(self.pk,))
@property
def transactions(self):
return apps.get_model("transaction", "Transaction").objects.filter(
statement__account=self
)
class Meta:
ordering = ["-default", "name"]
verbose_name = _("Account")

View file

@ -1,8 +1,8 @@
{% extends "main/base.html" %}
{% load main_extras statement_extras %}
{% load main_extras history_extras statement_extras %}
{% load i18n %}
{% block title %}
{{ object }} {{ block.super }}
{{ account }} {{ block.super }}
{% endblock title %}
{% block link %}
{{ block.super }}
@ -10,9 +10,9 @@
{% css "main/css/plot.css" %}
{% endblock link %}
{% block body %}
<h2>{{ object.icon|remix }}{{ object }}</h2>
<h2>{{ account.icon|remix }}{{ account }}</h2>
<p>
<a href="{% url "edit_account" object.pk %}">{{ "edit"|remix }}{% translate "Edit account" %}</a>
<a href="{% url "edit_account" account.pk %}">{{ "edit"|remix }}{% translate "Edit account" %}</a>
</p>
<section>
<h3>{% translate "Statements" %}</h3>
@ -20,10 +20,8 @@
{% url "account_statements" account=account.pk as s_url %}
{% statement_table account.statement_set.all statements_url=s_url new_statement_url=ns_url n_max=6 %}
</section>
{% if history %}
<section>
<h3>{% translate "History" %}</h3>
{% include "history/plot.html" %}
</section>
{% endif %}
<section>
<h3>{% translate "History" %}</h3>
{% history_plot account.transactions %}
</section>
{% endblock body %}

View file

@ -1,5 +1,4 @@
from django.shortcuts import get_object_or_404
from history.utils import history
from main.views import (
NummiCreateView,
NummiDeleteView,
@ -8,7 +7,6 @@ from main.views import (
NummiUpdateView,
)
from statement.views import StatementListView
from transaction.models import Transaction
from transaction.views import TransactionListView
from .forms import AccountForm
@ -34,14 +32,7 @@ class AccountDeleteView(NummiDeleteView):
class AccountDetailView(NummiDetailView):
model = Account
pk_url_kwarg = "account"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
account = data.get("object")
return data | {
"history": history(Transaction.objects.filter(statement__account=account)),
}
context_object_name = "account"
class AccountMixin: