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">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<div class="buttons">
|
||||
<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_buttons category %}
|
||||
</form>
|
||||
|
||||
{% if transactions %}
|
||||
|
|
|
@ -25,11 +25,7 @@
|
|||
<form action="{% url 'snapshot' snapshot.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<div class="buttons">
|
||||
<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_buttons snapshot %}
|
||||
</form>
|
||||
|
||||
{% 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" %}
|
||||
{% load static %}
|
||||
{% load main_extras %}
|
||||
|
||||
{% block link %}
|
||||
{{ block.super }}
|
||||
|
@ -14,11 +15,7 @@
|
|||
{% csrf_token %}
|
||||
<input type="hidden" name="form" value="transaction" />
|
||||
{{ form }}
|
||||
<div class="buttons">
|
||||
<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_buttons transaction %}
|
||||
</form>
|
||||
{% endspaceless %}
|
||||
|
||||
|
|
|
@ -32,3 +32,13 @@ def pmvalue(val):
|
|||
@register.inclusion_tag("main/tag/transaction_table.html")
|
||||
def transaction_table(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,
|
||||
"form": _form,
|
||||
"transactions": Transaction.objects.filter(category=_category),
|
||||
"adding": _category._state.adding,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -165,7 +166,9 @@ def snapshot(request, uuid=None):
|
|||
|
||||
if _snapshot.transactions:
|
||||
context["categories"] = (
|
||||
_snapshot.transactions.values("category", "category__name", "category__icon")
|
||||
_snapshot.transactions.values(
|
||||
"category", "category__name", "category__icon"
|
||||
)
|
||||
.annotate(
|
||||
sum=models.Sum("value"),
|
||||
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
||||
|
|
Loading…
Reference in a new issue