Add templating for form buttons
This commit is contained in:
parent
7269fcbc6b
commit
a10e798c8c
6 changed files with 29 additions and 16 deletions
|
@ -14,11 +14,7 @@
|
||||||
<form action="{% url 'category' category.id %}" method="post">
|
<form action="{% url 'category' category.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
<div class="buttons">
|
{% form_buttons category %}
|
||||||
<a href="{% url 'del_category' category.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
|
||||||
<input type="reset" />
|
|
||||||
<input type="submit" value="Save Category" />
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if transactions %}
|
{% if transactions %}
|
||||||
|
|
|
@ -25,11 +25,7 @@
|
||||||
<form action="{% url 'snapshot' snapshot.id %}" method="post">
|
<form action="{% url 'snapshot' snapshot.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
<div class="buttons">
|
{% form_buttons snapshot %}
|
||||||
<a href="{% url 'del_snapshot' snapshot.date %}"><input type="button" value="Delete" class="del" /></a>
|
|
||||||
<input type="reset" />
|
|
||||||
<input type="submit" value="Save Snapshot" />
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if categories %}
|
{% if categories %}
|
||||||
|
|
11
nummi/main/templates/main/tag/form_buttons.html
Normal file
11
nummi/main/templates/main/tag/form_buttons.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<div class="buttons">
|
||||||
|
{% if not adding %}
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
value="Delete"
|
||||||
|
class="btn del"
|
||||||
|
onclick="if(confirm('Supprimer <{{ instance.name}}> ?')) window.location.href = '{% url del_url instance.id %}'" />
|
||||||
|
{% endif %}
|
||||||
|
<input type="reset" />
|
||||||
|
<input type="submit" value="Save {{ name }}" />
|
||||||
|
</div>
|
|
@ -1,5 +1,6 @@
|
||||||
{% extends "main/base.html" %}
|
{% extends "main/base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load main_extras %}
|
||||||
|
|
||||||
{% block link %}
|
{% block link %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
@ -14,11 +15,7 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="form" value="transaction" />
|
<input type="hidden" name="form" value="transaction" />
|
||||||
{{ form }}
|
{{ form }}
|
||||||
<div class="buttons">
|
{% form_buttons transaction %}
|
||||||
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
|
||||||
<input class="btn" type="reset" />
|
|
||||||
<input class="btn" type="submit" value="Save Transaction" />
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
|
|
||||||
|
|
|
@ -32,3 +32,13 @@ def pmvalue(val):
|
||||||
@register.inclusion_tag("main/tag/transaction_table.html")
|
@register.inclusion_tag("main/tag/transaction_table.html")
|
||||||
def transaction_table(transactions):
|
def transaction_table(transactions):
|
||||||
return {"transactions": transactions}
|
return {"transactions": transactions}
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag("main/tag/form_buttons.html")
|
||||||
|
def form_buttons(instance):
|
||||||
|
return {
|
||||||
|
"instance": instance,
|
||||||
|
"adding": instance._state.adding,
|
||||||
|
"name": instance.__class__.__name__,
|
||||||
|
"del_url": f"del_{instance.__class__.__name__.lower()}"
|
||||||
|
}
|
||||||
|
|
|
@ -128,6 +128,7 @@ def category(request, uuid=None):
|
||||||
"category": _category,
|
"category": _category,
|
||||||
"form": _form,
|
"form": _form,
|
||||||
"transactions": Transaction.objects.filter(category=_category),
|
"transactions": Transaction.objects.filter(category=_category),
|
||||||
|
"adding": _category._state.adding,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -165,7 +166,9 @@ def snapshot(request, uuid=None):
|
||||||
|
|
||||||
if _snapshot.transactions:
|
if _snapshot.transactions:
|
||||||
context["categories"] = (
|
context["categories"] = (
|
||||||
_snapshot.transactions.values("category", "category__name", "category__icon")
|
_snapshot.transactions.values(
|
||||||
|
"category", "category__name", "category__icon"
|
||||||
|
)
|
||||||
.annotate(
|
.annotate(
|
||||||
sum=models.Sum("value"),
|
sum=models.Sum("value"),
|
||||||
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
||||||
|
|
Loading…
Reference in a new issue