Use templatetag for transaction_table
This commit is contained in:
parent
229033aac0
commit
348ac494e9
5 changed files with 28 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
||||||
{% extends "main/base.html" %}
|
{% extends "main/base.html" %}
|
||||||
{% load i18n main_extras history_extras %}
|
{% load i18n main_extras history_extras transaction_extras %}
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{{ category }} – {{ block.super }}
|
{{ category }} – {{ block.super }}
|
||||||
{% endblock title %}
|
{% endblock title %}
|
||||||
|
@ -15,7 +15,8 @@
|
||||||
</p>
|
</p>
|
||||||
<section>
|
<section>
|
||||||
<h3>{% translate "Transactions" %}</h3>
|
<h3>{% translate "Transactions" %}</h3>
|
||||||
{% include "transaction/transaction_table.html" %}
|
{% url "category_transactions" category.id as t_url %}
|
||||||
|
{% transaction_table category.transaction_set.all n_max=8 transactions_url=t_url %}
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h3>{% translate "History" %}</h3>
|
<h3>{% translate "History" %}</h3>
|
||||||
|
|
|
@ -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 main.views import (
|
from main.views import (
|
||||||
NummiCreateView,
|
NummiCreateView,
|
||||||
NummiDeleteView,
|
NummiDeleteView,
|
||||||
|
@ -28,19 +27,6 @@ class CategoryDetailView(NummiDetailView):
|
||||||
pk_url_kwarg = "category"
|
pk_url_kwarg = "category"
|
||||||
context_object_name = "category"
|
context_object_name = "category"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
_max = 8
|
|
||||||
data = super().get_context_data(**kwargs)
|
|
||||||
category = data["object"]
|
|
||||||
|
|
||||||
data["transactions"] = category.transaction_set.all()[:_max]
|
|
||||||
if len(data["transactions"]) == _max:
|
|
||||||
data["transactions_url"] = reverse_lazy(
|
|
||||||
"category_transactions", args=(category.pk,)
|
|
||||||
)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryDeleteView(NummiDeleteView):
|
class CategoryDeleteView(NummiDeleteView):
|
||||||
model = Category
|
model = Category
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
{% extends "main/base.html" %}
|
{% extends "main/base.html" %}
|
||||||
{% load i18n main_extras statement_extras category %}
|
{% load i18n main_extras statement_extras transaction_extras category %}
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{{ statement }}
|
{{ statement }}
|
||||||
– Nummi
|
– Nummi
|
||||||
{% endblock %}
|
{% endblock title %}
|
||||||
{% block link %}
|
{% block link %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
{% css "main/css/form.css" %}
|
{% css "main/css/form.css" %}
|
||||||
{% css "main/css/table.css" %}
|
{% css "main/css/table.css" %}
|
||||||
{% css "main/css/plot.css" %}
|
{% css "main/css/plot.css" %}
|
||||||
{% endblock %}
|
{% endblock link %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>{{ statement }}</h2>
|
<h2>{{ statement }}</h2>
|
||||||
<p>
|
<p>
|
||||||
|
@ -38,10 +38,12 @@
|
||||||
</div>
|
</div>
|
||||||
<section>
|
<section>
|
||||||
<h3>{% translate "Transactions" %}</h3>
|
<h3>{% translate "Transactions" %}</h3>
|
||||||
{% include "transaction/transaction_table.html" %}
|
{% url "statement_transactions" statement.id as t_url %}
|
||||||
|
{% url "new_transaction" statement=statement.id as nt_url %}
|
||||||
|
{% transaction_table statement.transaction_set.all n_max=8 transactions_url=t_url new_transaction_url=nt_url %}
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h3>{% translate "Categories" %}</h3>
|
<h3>{% translate "Categories" %}</h3>
|
||||||
{% category_plot transactions budget=False statement=object %}
|
{% category_plot transactions budget=False statement=object %}
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock body %}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{% extends "main/list.html" %}
|
{% extends "main/list.html" %}
|
||||||
{% load i18n %}
|
{% load i18n transaction_extras %}
|
||||||
{% block name %}
|
{% block name %}
|
||||||
{% translate "Transactions" %}
|
{% translate "Transactions" %}
|
||||||
{% endblock %}
|
{% endblock name %}
|
||||||
{% block h2 %}
|
{% block h2 %}
|
||||||
{% translate "Transactions" %}
|
{% translate "Transactions" %}
|
||||||
{% endblock %}
|
{% endblock h2 %}
|
||||||
{% block table %}
|
{% block table %}
|
||||||
{% url "new_transaction" as new_transaction_url %}
|
{% url "new_transaction" as nt_url %}
|
||||||
{% include "transaction/transaction_table.html" %}
|
{% transaction_table transactions new_transaction_url=nt_url %}
|
||||||
{% endblock %}
|
{% endblock table %}
|
||||||
|
|
|
@ -10,6 +10,18 @@ from ..utils import ac_url
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag("transaction/transaction_table.html")
|
||||||
|
def transaction_table(transactions, **kwargs):
|
||||||
|
if (n_max := kwargs.get("n_max")) is not None:
|
||||||
|
if transactions.count() <= n_max:
|
||||||
|
del kwargs["transactions_url"]
|
||||||
|
transactions = transactions[:n_max]
|
||||||
|
|
||||||
|
return kwargs | {
|
||||||
|
"transactions": transactions,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def month_url(context, month, cls="", fmt="Y-m"):
|
def month_url(context, month, cls="", fmt="Y-m"):
|
||||||
url_name, url_params = ac_url(
|
url_name, url_params = ac_url(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue