From 64b5b22defb6a369656efd4b218cc52460638afd Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 18 Apr 2023 15:14:52 +0200 Subject: [PATCH] Fix file input --- nummi/main/forms.py | 11 ++++++ nummi/main/static/main/css/form.css | 6 ++++ nummi/main/templates/main/form/fileinput.html | 34 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 nummi/main/templates/main/form/fileinput.html diff --git a/nummi/main/forms.py b/nummi/main/forms.py index 146432a..d1e5de1 100644 --- a/nummi/main/forms.py +++ b/nummi/main/forms.py @@ -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") diff --git a/nummi/main/static/main/css/form.css b/nummi/main/static/main/css/form.css index 90b8aa4..b081be4 100644 --- a/nummi/main/static/main/css/form.css +++ b/nummi/main/static/main/css/form.css @@ -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; diff --git a/nummi/main/templates/main/form/fileinput.html b/nummi/main/templates/main/form/fileinput.html new file mode 100644 index 0000000..7d6d7bc --- /dev/null +++ b/nummi/main/templates/main/form/fileinput.html @@ -0,0 +1,34 @@ + + {% if widget.is_initial %} + + + + + {% if not widget.required %} + + + + + {% endif %} + + + + + +
{{ widget.initial_text }} + Fichier +
+ + + +
{{ widget.input_text }} + {% else %} +
+ {% endif %} + +