Fix file input
This commit is contained in:
parent
74c95c7d16
commit
64b5b22def
3 changed files with 51 additions and 0 deletions
|
@ -5,6 +5,10 @@ from django.utils.translation import gettext_lazy as _
|
|||
from .models import Account, Category, Invoice, Snapshot, Transaction
|
||||
|
||||
|
||||
class NummiFileInput(forms.ClearableFileInput):
|
||||
template_name = "main/form/fileinput.html"
|
||||
|
||||
|
||||
class NummiForm(forms.ModelForm):
|
||||
template_name = "main/form/base.html"
|
||||
|
||||
|
@ -28,6 +32,7 @@ class CategoryForm(NummiForm):
|
|||
fields = [
|
||||
"name",
|
||||
"icon",
|
||||
"budget",
|
||||
]
|
||||
|
||||
|
||||
|
@ -62,12 +67,18 @@ class InvoiceForm(NummiForm):
|
|||
"name",
|
||||
"file",
|
||||
]
|
||||
widgets = {
|
||||
"file": NummiFileInput,
|
||||
}
|
||||
|
||||
|
||||
class SnapshotForm(NummiForm):
|
||||
class Meta:
|
||||
model = Snapshot
|
||||
fields = ["account", "start_date", "date", "start_value", "value", "file"]
|
||||
widgets = {
|
||||
"file": NummiFileInput,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
_user = kwargs.get("user")
|
||||
|
|
|
@ -15,6 +15,12 @@ form tbody textarea {
|
|||
height: 100%;
|
||||
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 {
|
||||
text-align: right;
|
||||
|
|
34
nummi/main/templates/main/form/fileinput.html
Normal file
34
nummi/main/templates/main/form/fileinput.html
Normal 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>
|
Loading…
Reference in a new issue