Add snapshot list view, general and per account

Closes #4
This commit is contained in:
Edgar P. Burkhart 2022-12-31 10:27:06 +01:00
parent acd83704af
commit 057734afd3
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
6 changed files with 111 additions and 44 deletions

View file

@ -43,46 +43,6 @@
{% endif %}
{% if snapshots %}
<h2>{% translate "Snapshots" %}</h2>
<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>
{% snapshot_table snapshots %}
{% endif %}
{% endblock %}

View file

@ -0,0 +1,36 @@
{% extends "main/base.html" %}
{% load static %}
{% load main_extras %}
{% load i18n %}
{% block link %}
{{ block.super }}
<link rel="stylesheet"
href="{% static 'main/css/table.css' %}"
type="text/css"/>
<link rel="stylesheet"
href="{% static 'main/css/page.css' %}"
type="text/css"/>
{% endblock %}
{% block body %}
<h1>{% translate "Statements" %}</h1>
{% if snapshots %}
{% snapshot_table snapshots %}
{% if page_obj %}
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1"></a>
<a href="?page={{ page_obj.previous_page_number }}"></a>
{% endif %}
<span class="current">{{ page_obj.number }}/{{ page_obj.paginator.num_pages }}</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}"></a>
<a href="?page={{ page_obj.paginator.num_pages }}"></a>
{% endif %}
</span>
</div>
{% endif %}
{% else %}
<p>{% translate "No snapshots to show" %}</p>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,43 @@
{% 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

@ -33,6 +33,11 @@ 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")
def form_buttons(instance):
return {

View file

@ -7,6 +7,7 @@ urlpatterns = [
path("login", views.LoginView.as_view(), name="login"),
path("logout", views.LogoutView.as_view(), name="logout"),
path("transactions", views.TransactionListView.as_view(), name="transactions"),
path("snapshots", views.SnapshotListView.as_view(), name="snapshots"),
path("account", views.AccountCreateView.as_view(), name="account"),
path("transaction", views.TransactionCreateView.as_view(), name="transaction"),
path(
@ -22,6 +23,11 @@ urlpatterns = [
views.AccountTListView.as_view(),
name="account_transactions",
),
path(
"account/<pk>/snapshots",
views.AccountSListView.as_view(),
name="account_snapshots",
),
path("transaction/<pk>", views.TransactionUpdateView.as_view(), name="transaction"),
path(
"transaction/<transaction_pk>/invoice/<pk>",

View file

@ -30,7 +30,7 @@ class IndexView(LoginRequiredMixin, TemplateView):
"accounts": Account.objects.filter(user=self.request.user),
"transactions": Transaction.objects.filter(user=self.request.user)[:10],
"categories": Category.objects.filter(user=self.request.user),
"snapshots": Snapshot.objects.filter(user=self.request.user),
"snapshots": Snapshot.objects.filter(user=self.request.user)[:10],
}
@ -173,18 +173,35 @@ class SnapshotDeleteView(NummiDeleteView):
model = Snapshot
class TransactionListView(UserMixin, ListView):
class NummiListView(UserMixin, ListView):
paginate_by = 24
class TransactionListView(NummiListView):
model = Transaction
template_name = "main/transactions.html"
context_object_name = "transactions"
class AccountTListView(TransactionListView):
class SnapshotListView(NummiListView):
model = Snapshot
template_name = "main/snapshots.html"
context_object_name = "snapshots"
class AccountMixin:
def get_queryset(self):
return super().get_queryset().filter(account=self.kwargs.get("pk"))
class AccountTListView(AccountMixin, TransactionListView):
pass
class AccountSListView(AccountMixin, SnapshotListView):
pass
class SnapshotTListView(TransactionListView):
def get_queryset(self):
return super().get_queryset().filter(snapshot=self.kwargs.get("pk"))