Fix file input

This commit is contained in:
Edgar P. Burkhart 2023-04-18 15:14:52 +02:00
parent 74c95c7d16
commit 64b5b22def
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 51 additions and 0 deletions

View file

@ -5,6 +5,10 @@ from django.utils.translation import gettext_lazy as _
from .models import Account, Category, Invoice, Snapshot, Transaction from .models import Account, Category, Invoice, Snapshot, Transaction
class NummiFileInput(forms.ClearableFileInput):
template_name = "main/form/fileinput.html"
class NummiForm(forms.ModelForm): class NummiForm(forms.ModelForm):
template_name = "main/form/base.html" template_name = "main/form/base.html"
@ -28,6 +32,7 @@ class CategoryForm(NummiForm):
fields = [ fields = [
"name", "name",
"icon", "icon",
"budget",
] ]
@ -62,12 +67,18 @@ class InvoiceForm(NummiForm):
"name", "name",
"file", "file",
] ]
widgets = {
"file": NummiFileInput,
}
class SnapshotForm(NummiForm): class SnapshotForm(NummiForm):
class Meta: class Meta:
model = Snapshot model = Snapshot
fields = ["account", "start_date", "date", "start_value", "value", "file"] fields = ["account", "start_date", "date", "start_value", "value", "file"]
widgets = {
"file": NummiFileInput,
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
_user = kwargs.get("user") _user = kwargs.get("user")

View file

@ -15,6 +15,12 @@ form tbody textarea {
height: 100%; height: 100%;
line-height: 1.5; line-height: 1.5;
} }
form input[type="checkbox"] {width: initial}
table.file-input tr {border: none}
table.file-input th {
text-align: left;
padding: 0;
}
form tfoot { form tfoot {
text-align: right; text-align: right;

View file

@ -0,0 +1,34 @@
<table class="file-input">
{% if widget.is_initial %}
<tr>
<th>{{ widget.initial_text }}</th>
<td>
<a href="{{ widget.value.url }}">Fichier</a>
</td>
</tr>
{% if not widget.required %}
<tr>
<th>
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>
</th>
<td>
<input type="checkbox"
name="{{ widget.checkbox_name }}"
id="{{ widget.checkbox_id }}"
{% if widget.attrs.disabled %}disabled{% endif %}>
</td>
</tr>
{% endif %}
<tr>
<th>{{ widget.input_text }}</th>
<td>
{% else %}
<tr>
<td colspan="2">
{% endif %}
<input type="{{ widget.type }}"
name="{{ widget.name }}"
{% include "django/forms/widgets/attrs.html" %}>
</td>
</tr>
</table>