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
|
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")
|
||||||
|
|
|
@ -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;
|
||||||
|
|
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