Fix bugs and update templating
This commit is contained in:
parent
5d6f47b852
commit
df0882bd88
9 changed files with 105 additions and 100 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 4.0.4 on 2022-05-22 09:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("main", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="snapshot",
|
||||||
|
name="date",
|
||||||
|
field=models.DateField(unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="snapshot",
|
||||||
|
name="diff",
|
||||||
|
field=models.DecimalField(
|
||||||
|
blank=True, decimal_places=2, editable=False, max_digits=12, null=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -82,7 +82,7 @@ class Snapshot(models.Model):
|
||||||
"self", on_delete=models.SET_NULL, blank=True, null=True, editable=False
|
"self", on_delete=models.SET_NULL, blank=True, null=True, editable=False
|
||||||
)
|
)
|
||||||
diff = models.DecimalField(
|
diff = models.DecimalField(
|
||||||
max_digits=12, decimal_places=2, default=0, editable=False
|
max_digits=12, decimal_places=2, editable=False, blank=True, null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -105,11 +105,18 @@ class Snapshot(models.Model):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
_prevnext = self.__class__.objects.exclude(id=self.id).get(previous=self)
|
_prevnext = self.__class__.objects.exclude(id=self.id).get(
|
||||||
|
previous=self
|
||||||
|
)
|
||||||
except self.__class__.DoesNotExist:
|
except self.__class__.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
_prevnext.previous = self.__class__.objects.order_by("-date").exclude(id=self.id).filter(date__lt=_prevnext.date).first()
|
_prevnext.previous = (
|
||||||
|
self.__class__.objects.order_by("-date")
|
||||||
|
.exclude(id=self.id)
|
||||||
|
.filter(date__lt=_prevnext.date)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
_prevnext.save(only_super=True)
|
_prevnext.save(only_super=True)
|
||||||
_next.previous = self
|
_next.previous = self
|
||||||
_next.save(only_super=True)
|
_next.save(only_super=True)
|
||||||
|
@ -117,7 +124,7 @@ class Snapshot(models.Model):
|
||||||
self.previous = _prev
|
self.previous = _prev
|
||||||
|
|
||||||
if self.previous is None:
|
if self.previous is None:
|
||||||
self.diff = 0
|
self.diff = None
|
||||||
else:
|
else:
|
||||||
self.diff = self.value - self.previous.value
|
self.diff = self.value - self.previous.value
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
|
@ -26,35 +26,6 @@
|
||||||
|
|
||||||
{% if transactions %}
|
{% if transactions %}
|
||||||
<h2>Transactions</h2>
|
<h2>Transactions</h2>
|
||||||
|
{% transaction_table transactions %}
|
||||||
<div id="transactions" class="table col6">
|
|
||||||
<div class="header">
|
|
||||||
<strong class="date center">Date</strong>
|
|
||||||
<strong class="name">Nom</strong>
|
|
||||||
<strong class="value center">Valeur</strong>
|
|
||||||
<strong class="trader center">Commerçant</strong>
|
|
||||||
<strong class="category center">Catégorie</strong>
|
|
||||||
<strong class="description">Description</strong>
|
|
||||||
</div>
|
|
||||||
{% for trans in transactions %}
|
|
||||||
<div class="transaction {% cycle 'w' 'g' %}">
|
|
||||||
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
|
|
||||||
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
|
|
||||||
<span class="value num right">{{ trans.value|floatformat:"2g"|pm }} €</span>
|
|
||||||
<span class="trader text center">{{ trans.trader|default_if_none:"–" }}</span>
|
|
||||||
<span class="category text center">
|
|
||||||
{% if trans.category %}
|
|
||||||
<i class="fa fa-{{ trans.category.icon }}"></i>
|
|
||||||
<a href="{% url 'category' trans.category.id %}">
|
|
||||||
{{ trans.category }}
|
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
–
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
<span class="description text">{{ trans.description }}</span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -12,35 +12,8 @@
|
||||||
<h1>Nummi</h1>
|
<h1>Nummi</h1>
|
||||||
|
|
||||||
{% if transactions %}
|
{% if transactions %}
|
||||||
<div id="transactions" class="table col6">
|
<h2>Transactions</h2>
|
||||||
<div class="header">
|
{% transaction_table transactions %}
|
||||||
<strong class="date center">Date</strong>
|
|
||||||
<strong class="name">Nom</strong>
|
|
||||||
<strong class="value center">Valeur</strong>
|
|
||||||
<strong class="trader center">Commerçant</strong>
|
|
||||||
<strong class="category center">Catégorie</strong>
|
|
||||||
<strong class="description">Description</strong>
|
|
||||||
</div>
|
|
||||||
{% for trans in transactions %}
|
|
||||||
<div class="transaction {% cycle 'w' 'g' %}">
|
|
||||||
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
|
|
||||||
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
|
|
||||||
<span class="value num right">{{ trans.value|floatformat:"2g"|pm }} €</span>
|
|
||||||
<span class="trader text center">{{ trans.trader|default_if_none:"–" }}</span>
|
|
||||||
<span class="category text center">
|
|
||||||
{% if trans.category %}
|
|
||||||
<i class="fa fa-{{ trans.category.icon }}"></i>
|
|
||||||
<a href="{% url 'category' trans.category.id %}">
|
|
||||||
{{ trans.category }}
|
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
–
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
<span class="description text">{{ trans.description }}</span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if snapshots %}
|
{% if snapshots %}
|
||||||
|
@ -58,11 +31,13 @@
|
||||||
<span class="date num center">
|
<span class="date num center">
|
||||||
<a href="{% url 'snapshot' snap.date %}">{{ snap.date|date:"Y-m-d" }}</a>
|
<a href="{% url 'snapshot' snap.date %}">{{ snap.date|date:"Y-m-d" }}</a>
|
||||||
</span>
|
</span>
|
||||||
<span class="value num right">{{ snap.value|floatformat:"2g" }} €</span>
|
<span class="value num right">{% value snap.value %}</span>
|
||||||
<span class="diff num right">{{ snap.diff|floatformat:"2g"|pm }} €</span>
|
<span class="diff num right">
|
||||||
|
{% pmvalue snap.diff %}
|
||||||
|
</span>
|
||||||
{% with sum=snap.sum %}
|
{% with sum=snap.sum %}
|
||||||
<span class="sum num right">
|
<span class="sum num right">
|
||||||
{% if sum is not None %}{{ sum|floatformat:"2g"|pm }} €{% endif %}
|
{% pmvalue sum %}
|
||||||
</span>
|
</span>
|
||||||
<span class="valid center">
|
<span class="valid center">
|
||||||
{% if snap.previous is not None %}
|
{% if snap.previous is not None %}
|
||||||
|
|
|
@ -36,37 +36,9 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if transactions %}
|
{% if transactions %}
|
||||||
<h2>Transactions ({{ sum|floatformat:"2g"|pm }} € / {{ snapshot.diff|floatformat:"2g"|pm }} €)</h2>
|
<h2>Transactions ({% pmvalue sum %} / {% pmvalue snapshot.diff %})</h2>
|
||||||
|
|
||||||
<div id="transactions" class="table col6">
|
{% transaction_table transactions %}
|
||||||
<div class="header">
|
|
||||||
<strong class="date center">Date</strong>
|
|
||||||
<strong class="name">Nom</strong>
|
|
||||||
<strong class="value center">Valeur</strong>
|
|
||||||
<strong class="trader center">Commerçant</strong>
|
|
||||||
<strong class="category center">Catégorie</strong>
|
|
||||||
<strong class="description">Description</strong>
|
|
||||||
</div>
|
|
||||||
{% for trans in transactions %}
|
|
||||||
<div class="transaction {% cycle 'w' 'g' %}">
|
|
||||||
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
|
|
||||||
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
|
|
||||||
<span class="value num right">{{ trans.value|floatformat:"2g"|pm }} €</span>
|
|
||||||
<span class="trader text center">{{ trans.trader|default_if_none:"–" }}</span>
|
|
||||||
<span class="category text center">
|
|
||||||
{% if trans.category %}
|
|
||||||
<i class="fa fa-{{ trans.category.icon }}"></i>
|
|
||||||
<a href="{% url 'category' trans.category.id %}">
|
|
||||||
{{ trans.category }}
|
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
–
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
<span class="description text">{{ trans.description }}</span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
8
nummi/main/templates/main/tag/pmvalue.html
Normal file
8
nummi/main/templates/main/tag/pmvalue.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{% extends "main/tag/value.html" %}
|
||||||
|
|
||||||
|
{% block "value" %}
|
||||||
|
{% if value %}
|
||||||
|
{% if value > 0 %}+{% endif %}
|
||||||
|
{{ block.super }}
|
||||||
|
{% else %}–{% endif %}
|
||||||
|
{% endblock %}
|
31
nummi/main/templates/main/tag/transaction_table.html
Normal file
31
nummi/main/templates/main/tag/transaction_table.html
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{% load main_extras %}
|
||||||
|
|
||||||
|
<div id="transactions" class="table col6">
|
||||||
|
<div class="header">
|
||||||
|
<strong class="date center">Date</strong>
|
||||||
|
<strong class="name">Nom</strong>
|
||||||
|
<strong class="value center">Valeur</strong>
|
||||||
|
<strong class="trader center">Commerçant</strong>
|
||||||
|
<strong class="category center">Catégorie</strong>
|
||||||
|
<strong class="description">Description</strong>
|
||||||
|
</div>
|
||||||
|
{% for trans in transactions %}
|
||||||
|
<div class="transaction {% cycle 'w' 'g' %}">
|
||||||
|
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
|
||||||
|
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
|
||||||
|
<span class="value num right">{% pmvalue trans.value %}</span>
|
||||||
|
<span class="trader text center">{{ trans.trader|default_if_none:"–" }}</span>
|
||||||
|
<span class="category text center">
|
||||||
|
{% if trans.category %}
|
||||||
|
<i class="fa fa-{{ trans.category.icon }}"></i>
|
||||||
|
<a href="{% url 'category' trans.category.id %}">
|
||||||
|
{{ trans.category }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
–
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
<span class="description text">{{ trans.description }}</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
7
nummi/main/templates/main/tag/value.html
Normal file
7
nummi/main/templates/main/tag/value.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% spaceless %}
|
||||||
|
<span>
|
||||||
|
{% block "value" %}
|
||||||
|
{{ value|floatformat:"2g" }} €
|
||||||
|
{% endblock %}
|
||||||
|
</span>
|
||||||
|
{% endspaceless %}
|
|
@ -4,7 +4,16 @@ from django.template.defaultfilters import stringfilter
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.inclusion_tag("main/tag/value.html")
|
||||||
@stringfilter
|
def value(value):
|
||||||
def pm(value):
|
return {"value": value}
|
||||||
return f"{'+' if value[0] != '-' else ''}{value}"
|
|
||||||
|
|
||||||
|
@register.inclusion_tag("main/tag/pmvalue.html")
|
||||||
|
def pmvalue(value):
|
||||||
|
return {"value": value}
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag("main/tag/transaction_table.html")
|
||||||
|
def transaction_table(transactions):
|
||||||
|
return {"transactions": transactions}
|
||||||
|
|
Loading…
Reference in a new issue