Update templates with new snapshot and transaction tables

Add link on homepage to see all transactions and snapshots
This commit is contained in:
Edgar P. Burkhart 2022-12-31 11:05:30 +01:00
parent 057734afd3
commit 9c978723ef
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
11 changed files with 78 additions and 68 deletions

View file

@ -49,3 +49,7 @@
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.table > div.full-line > * {
grid-column: 1 / -1;
text-align: center;
}

View file

@ -23,6 +23,8 @@
<img src="{% url "plot-category" form.instance.id %}" <img src="{% url "plot-category" form.instance.id %}"
alt="Graph representing value over time"/> alt="Graph representing value over time"/>
<h2>{% translate "Transactions" %}</h2> <h2>{% translate "Transactions" %}</h2>
{% transaction_table form.instance.transactions %} {% with transactions=form.instance.transactions %}
{% include "main/table/transaction.html" %}
{% endwith %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -23,13 +23,8 @@
{% endspaceless %} {% endspaceless %}
{% endif %} {% endif %}
{% if transactions %} {% if transactions %}
<h2> <h2>{% translate "Transactions" %}</h2>
{% translate "Transactions" %} {% include "main/table/transaction.html" %}
<a href="{% url "transactions" %}">
<i class="fa fa-magnifying-glass-plus"></i>
</a>
</h2>
{% transaction_table transactions %}
{% endif %} {% endif %}
{% if categories %} {% if categories %}
<h2>{% translate "Categories" %}</h2> <h2>{% translate "Categories" %}</h2>
@ -43,6 +38,6 @@
{% endif %} {% endif %}
{% if snapshots %} {% if snapshots %}
<h2>{% translate "Snapshots" %}</h2> <h2>{% translate "Snapshots" %}</h2>
{% snapshot_table snapshots %} {% include "main/table/snapshot.html" %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -14,7 +14,7 @@
{% block body %} {% block body %}
<h1>{% translate "Statements" %}</h1> <h1>{% translate "Statements" %}</h1>
{% if snapshots %} {% if snapshots %}
{% snapshot_table snapshots %} {% include "main/table/snapshot.html" %}
{% if page_obj %} {% if page_obj %}
<div class="pagination"> <div class="pagination">
<span class="step-links"> <span class="step-links">

View file

@ -14,7 +14,7 @@
{% block body %} {% block body %}
<h1>{% translate "Transactions" %}</h1> <h1>{% translate "Transactions" %}</h1>
{% if transactions %} {% if transactions %}
{% transaction_table transactions %} {% include "main/table/transaction.html" %}
{% if page_obj %} {% if page_obj %}
<div class="pagination"> <div class="pagination">
<span class="step-links"> <span class="step-links">

View file

@ -73,7 +73,9 @@
{% endif %} {% endif %}
{% if snapshot.transaction_set.all %} {% if snapshot.transaction_set.all %}
<h2>{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2> <h2>{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
{% transaction_table snapshot.transaction_set.all %} {% with transactions=snapshot.transaction_set.all %}
{% include "main/table/transaction.html" %}
{% endwith %}
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% endblock %} {% endblock %}

View file

@ -0,0 +1,48 @@
{% load main_extras %}
{% load i18n %}
<div id="snapshots" class="table col1-6">
<div class="header">
<strong class="attach center"><i class="fa fa-paperclip"></i></strong>
<strong class="date center">{% translate "Date" %}</strong>
<strong class="account center">{% translate "Account" %}</strong>
<strong class="value center">{% translate "Value" %}</strong>
<strong class="diff center">{% translate "Difference" %}</strong>
<strong class="diff center">{% translate "Transactions" %}</strong>
<strong class="diff center">{% translate "Valid" %}</strong>
</div>
{% for snap in snapshots %}
<div class="snapshot {% cycle 'w' 'g' %}">
<span class="attach center">
{% if snap.file %}
<a href="{{ snap.file.url }}">
<i class="fa fa-paperclip"></i>
</a>
{% endif %}
</span>
<span class="date num center">
<a href="{% url 'snapshot' snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
</span>
<span class="account text center">
<i class="fa fa-{{ snap.account.icon }}"></i>
<a href="{% url 'account' snap.account.id %}">{{ snap.account }}</a>
</span>
<span class="value num right">{{ snap.value|value }}</span>
<span class="diff num right">{{ snap.diff|pmvalue }}</span>
{% with sum=snap.sum %}
<span class="sum num right">{{ sum|pmvalue }}</span>
<span class="valid center">
{% if sum == snap.diff %}
<i class="fa fa-check green"></i>
{% else %}
<i class="fa fa-xmark red"></i>
{% endif %}
</span>
{% endwith %}
</div>
{% endfor %}
{% if snapshots_url %}
<div class="full-line {% cycle "w" "g" %}">
<a href="{{ snapshots_url }}">{% translate "View all statements" %}</a>
</div>
{% endif %}
</div>

View file

@ -45,4 +45,9 @@
<span class="description text">{{ trans.description }}</span> <span class="description text">{{ trans.description }}</span>
</div> </div>
{% endfor %} {% endfor %}
{% if transactions_url %}
<div class="full-line {% cycle "w" "g" %}">
<a href="{{ transactions_url }}">{% translate "View all transactions" %}</a>
</div>
{% endif %}
</div> </div>

View file

@ -1,43 +0,0 @@
{% load main_extras %}
{% load i18n %}
<div id="snapshots" class="table col1-6">
<div class="header">
<strong class="attach center"><i class="fa fa-paperclip"></i></strong>
<strong class="date center">{% translate "Date" %}</strong>
<strong class="account center">{% translate "Account" %}</strong>
<strong class="value center">{% translate "Value" %}</strong>
<strong class="diff center">{% translate "Difference" %}</strong>
<strong class="diff center">{% translate "Transactions" %}</strong>
<strong class="diff center">{% translate "Valid" %}</strong>
</div>
{% for snap in snapshots %}
<div class="snapshot {% cycle 'w' 'g' %}">
<span class="attach center">
{% if snap.file %}
<a href="{{ snap.file.url }}">
<i class="fa fa-paperclip"></i>
</a>
{% endif %}
</span>
<span class="date num center">
<a href="{% url 'snapshot' snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
</span>
<span class="account text center">
<i class="fa fa-{{ snap.account.icon }}"></i>
<a href="{% url 'account' snap.account.id %}">{{ snap.account }}</a>
</span>
<span class="value num right">{{ snap.value|value }}</span>
<span class="diff num right">{{ snap.diff|pmvalue }}</span>
{% with sum=snap.sum %}
<span class="sum num right">{{ sum|pmvalue }}</span>
<span class="valid center">
{% if sum == snap.diff %}
<i class="fa fa-check green"></i>
{% else %}
<i class="fa fa-xmark red"></i>
{% endif %}
</span>
{% endwith %}
</div>
{% endfor %}
</div>

View file

@ -28,16 +28,6 @@ def pmvalue(val):
return value(val, True) return value(val, True)
@register.inclusion_tag("main/tag/transaction_table.html")
def transaction_table(transactions):
return {"transactions": transactions}
@register.inclusion_tag("main/tag/snapshot_table.html")
def snapshot_table(snapshots):
return {"snapshots": snapshots}
@register.inclusion_tag("main/tag/form_buttons.html") @register.inclusion_tag("main/tag/form_buttons.html")
def form_buttons(instance): def form_buttons(instance):
return { return {

View file

@ -26,12 +26,19 @@ 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):
return super().get_context_data(**kwargs) | { _max = 10
res = super().get_context_data(**kwargs) | {
"accounts": Account.objects.filter(user=self.request.user), "accounts": Account.objects.filter(user=self.request.user),
"transactions": Transaction.objects.filter(user=self.request.user)[:10], "transactions": Transaction.objects.filter(user=self.request.user)[:10],
"categories": Category.objects.filter(user=self.request.user), "categories": Category.objects.filter(user=self.request.user),
"snapshots": Snapshot.objects.filter(user=self.request.user)[:10], "snapshots": Snapshot.objects.filter(user=self.request.user)[:10],
} }
if res["transactions"].count() == 10:
res["transactions_url"] = reverse_lazy("transactions")
if res["snapshots"].count() == 10:
res["snapshots_url"] = (reverse_lazy("snapshots"),)
return res
class UserMixin(LoginRequiredMixin): class UserMixin(LoginRequiredMixin):
@ -179,13 +186,13 @@ class NummiListView(UserMixin, ListView):
class TransactionListView(NummiListView): class TransactionListView(NummiListView):
model = Transaction model = Transaction
template_name = "main/transactions.html" template_name = "main/list/transaction.html"
context_object_name = "transactions" context_object_name = "transactions"
class SnapshotListView(NummiListView): class SnapshotListView(NummiListView):
model = Snapshot model = Snapshot
template_name = "main/snapshots.html" template_name = "main/list/snapshot.html"
context_object_name = "snapshots" context_object_name = "snapshots"