Use templatetag for statement_table
This commit is contained in:
parent
786d7c2130
commit
b1fddd0dd6
7 changed files with 20 additions and 37 deletions
|
@ -16,7 +16,9 @@
|
||||||
</p>
|
</p>
|
||||||
<section>
|
<section>
|
||||||
<h3>{% translate "Statements" %}</h3>
|
<h3>{% translate "Statements" %}</h3>
|
||||||
{% statement_table statements statements_url=statements_url new_statement_url=new_statement_url %}
|
{% url "new_statement" account=account.pk as ns_url %}
|
||||||
|
{% 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>
|
</section>
|
||||||
{% if history %}
|
{% if history %}
|
||||||
<section>
|
<section>
|
||||||
|
|
|
@ -15,11 +15,9 @@
|
||||||
<dt>
|
<dt>
|
||||||
<a href="{% url "accounts" %}">{{ "gallery-view"|remixnl }}{% translate "All accounts" %}</a>
|
<a href="{% url "accounts" %}">{{ "gallery-view"|remixnl }}{% translate "All accounts" %}</a>
|
||||||
</dt>
|
</dt>
|
||||||
{% if total %}
|
|
||||||
<dd class="value">
|
<dd class="value">
|
||||||
{{ total|value }}
|
{{ accounts|balance|value }}
|
||||||
</dd>
|
</dd>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="more account">
|
<div class="more account">
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from history.utils import history
|
from history.utils import history
|
||||||
from main.views import (
|
from main.views import (
|
||||||
NummiCreateView,
|
NummiCreateView,
|
||||||
|
@ -37,21 +36,10 @@ class AccountDetailView(NummiDetailView):
|
||||||
pk_url_kwarg = "account"
|
pk_url_kwarg = "account"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
_max = 6
|
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
account = data.get("object")
|
account = data.get("object")
|
||||||
|
|
||||||
_statements = account.statement_set.all()
|
|
||||||
if _statements.count() > _max:
|
|
||||||
data["statements_url"] = reverse_lazy(
|
|
||||||
"account_statements", args=(account.pk,)
|
|
||||||
)
|
|
||||||
|
|
||||||
return data | {
|
return data | {
|
||||||
"new_statement_url": reverse_lazy(
|
|
||||||
"new_statement", kwargs={"account": account.pk}
|
|
||||||
),
|
|
||||||
"statements": _statements[:_max],
|
|
||||||
"history": history(Transaction.objects.filter(statement__account=account)),
|
"history": history(Transaction.objects.filter(statement__account=account)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,18 +12,19 @@
|
||||||
<div class="split">
|
<div class="split">
|
||||||
<section>
|
<section>
|
||||||
<h2>{% translate "Accounts" %}</h2>
|
<h2>{% translate "Accounts" %}</h2>
|
||||||
{% account_table accounts index=True total=accounts|balance %}
|
{% account_table user.account_set.all index=True %}
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>{% translate "Statements" %}</h2>
|
<h2>{% translate "Statements" %}</h2>
|
||||||
{% statement_table statements statements_url=statements_url %}
|
{% url "statements" as s_url %}
|
||||||
|
{% statement_table statements statements_url=s_url %}
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<section>
|
<section>
|
||||||
<h2>{% translate "Categories" %}</h2>
|
<h2>{% translate "Categories" %}</h2>
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
<p>
|
<p>
|
||||||
{% for cat in categories %}
|
{% for cat in user.category_set.all %}
|
||||||
<a class="category" href="{{ cat.get_absolute_url }}">{{ cat.icon|remix }}{{ cat }}</a>
|
<a class="category" href="{{ cat.get_absolute_url }}">{{ cat.icon|remix }}{{ cat }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<a class="category add" href="{% url "new_category" %}">{{ "add"|remix }}{% translate "Create category" %}</a>
|
<a class="category add" href="{% url "new_category" %}">{{ "add"|remix }}{% translate "Create category" %}</a>
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from account.models import Account
|
|
||||||
from category.models import Category
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
@ -15,33 +13,24 @@ from django.views.generic import (
|
||||||
UpdateView,
|
UpdateView,
|
||||||
)
|
)
|
||||||
from history.utils import history
|
from history.utils import history
|
||||||
from statement.models import Statement
|
|
||||||
from transaction.models import Transaction
|
|
||||||
|
|
||||||
|
|
||||||
class IndexView(LoginRequiredMixin, TemplateView):
|
class IndexView(LoginRequiredMixin, TemplateView):
|
||||||
template_name = "main/index.html"
|
template_name = "main/index.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
_max = 8
|
_user = self.request.user
|
||||||
_transactions = Transaction.objects.filter(user=self.request.user)
|
_transactions = _user.transaction_set.all()
|
||||||
_accounts = Account.objects.filter(user=self.request.user)
|
|
||||||
_statements = (
|
_statements = (
|
||||||
Statement.objects.filter(user=self.request.user)
|
_user.statement_set.exclude(account__archived=True)
|
||||||
.exclude(account__archived=True)
|
|
||||||
.order_by("account__id", "-date")
|
.order_by("account__id", "-date")
|
||||||
.distinct("account__id")
|
.distinct("account__id")
|
||||||
)
|
)
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
"accounts": _accounts,
|
|
||||||
"categories": Category.objects.filter(user=self.request.user),
|
|
||||||
"statements": _statements,
|
"statements": _statements,
|
||||||
"history": history(_transactions.exclude(category__budget=False)),
|
"history": history(_transactions.exclude(category__budget=False)),
|
||||||
}
|
}
|
||||||
if _transactions.count() > _max:
|
|
||||||
res["transactions_url"] = reverse_lazy("transactions")
|
|
||||||
res["statements_url"] = reverse_lazy("statements")
|
|
||||||
|
|
||||||
return super().get_context_data(**kwargs) | res
|
return super().get_context_data(**kwargs) | res
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
{% translate "Statements" %}
|
{% translate "Statements" %}
|
||||||
{% endblock h2 %}
|
{% endblock h2 %}
|
||||||
{% block table %}
|
{% block table %}
|
||||||
{% url "new_statement" as new_statement_url %}
|
{% url "new_statement" as ns_url %}
|
||||||
{% statement_table statements new_statement_url=new_statement_url %}
|
{% statement_table statements new_statement_url=ns_url %}
|
||||||
{% endblock table %}
|
{% endblock table %}
|
||||||
|
|
|
@ -16,6 +16,11 @@ def check(s, diff):
|
||||||
|
|
||||||
@register.inclusion_tag("statement/statement_table.html")
|
@register.inclusion_tag("statement/statement_table.html")
|
||||||
def statement_table(statements, **kwargs):
|
def statement_table(statements, **kwargs):
|
||||||
|
if (n_max := kwargs.get("n_max")) is not None:
|
||||||
|
if statements.count() <= n_max:
|
||||||
|
del kwargs["statements_url"]
|
||||||
|
statements = statements[:n_max]
|
||||||
|
|
||||||
return kwargs | {
|
return kwargs | {
|
||||||
"statements": statements,
|
"statements": statements,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue