11import datetime
22
3- from crispy_forms .helper import FormHelper
4- from crispy_forms .layout import Div , Layout
3+ import select2 .fields
54from django import forms
65from django .core .exceptions import ValidationError
76from django .db .models import Q
8- from unfold .widgets import (
9- UnfoldAdminDecimalFieldWidget ,
10- UnfoldAdminFileFieldWidget ,
11- UnfoldAdminSelect2Widget ,
12- UnfoldAdminSelectWidget ,
13- UnfoldAdminTextInputWidget ,
14- )
157
8+ ## Don't use unfold widgets yet, because first the templated have to be adapted
9+ # from unfold.widgets import (
10+ # UnfoldAdminDecimalFieldWidget,
11+ # UnfoldAdminFileFieldWidget,
12+ # UnfoldAdminSelect2Widget,
13+ # UnfoldAdminSelectWidget,
14+ # UnfoldAdminTextInputWidget,
15+ # )
16+ # from crispy_forms.helper import FormHelper
17+ # from crispy_forms.layout import Div, Layout
1618from geno .models import Address , Contract
1719
1820from .accounts import get_transaction_time_filter_options
@@ -32,34 +34,40 @@ class TransactionFilterForm(forms.Form):
3234 search = forms .CharField (
3335 label = "Suche" ,
3436 required = False ,
35- widget = UnfoldAdminTextInputWidget (attrs = {"size" : "40" , "autofocus" : True }),
37+ # widget=UnfoldAdminTextInputWidget(attrs={"size": "40", "autofocus": True}),
38+ widget = forms .TextInput (attrs = {"size" : "40" , "autofocus" : True }),
3639 )
3740 time = forms .ChoiceField (
3841 choices = get_transaction_time_filter_options (),
3942 label = "Zeitraum" ,
4043 required = False ,
41- widget = UnfoldAdminSelectWidget (),
44+ # widget=UnfoldAdminSelectWidget(),
4245 )
4346 sign_options = [
4447 ("all" , "Alle Buchungen" ),
4548 ("plus" , "Gutschriften" ),
4649 ("minus" , "Lastschriften" ),
4750 ]
4851 sign = forms .ChoiceField (
49- choices = sign_options , label = "Typ" , required = False , widget = UnfoldAdminSelectWidget ()
50- )
51- amount_min = forms .DecimalField (
52- label = "Betrag min." ,
53- required = False ,
54- decimal_places = 2 ,
55- widget = UnfoldAdminDecimalFieldWidget (),
56- )
57- amount_max = forms .DecimalField (
58- label = "Betrag max." ,
59- required = False ,
60- decimal_places = 2 ,
61- widget = UnfoldAdminDecimalFieldWidget (),
52+ choices = sign_options ,
53+ label = "Typ" ,
54+ required = False , # widget=UnfoldAdminSelectWidget()
6255 )
56+ amount_min = forms .FloatField (label = "Betrag min." , required = False )
57+ amount_max = forms .FloatField (label = "Betrag max." , required = False )
58+ ## TODO: DecimalField does not work yet because it is not JSON serializable in the session
59+ # amount_min = forms.DecimalField(
60+ # label="Betrag min.",
61+ # required=False,
62+ # decimal_places=2,
63+ # # widget=UnfoldAdminDecimalFieldWidget(),
64+ # )
65+ # amount_max = forms.DecimalField(
66+ # label="Betrag max.",
67+ # required=False,
68+ # decimal_places=2,
69+ # # widget=UnfoldAdminDecimalFieldWidget(),
70+ # )
6371
6472 def __init__ (self , * args , ** kwargs ):
6573 accounts = kwargs .pop ("accounts" , [])
@@ -68,28 +76,30 @@ def __init__(self, *args, **kwargs):
6876 account_options = [(account .id , str (account )) for account in accounts ]
6977 if admin :
7078 account_options .append (("_all_" , "== ALLE ==" ))
71- self .fields ["account" ] = forms .ChoiceField (
72- choices = account_options , label = "Konto" , widget = UnfoldAdminSelect2Widget ()
73- )
79+ self .fields ["account" ] = select2 .fields .ChoiceField (choices = account_options , label = "Konto" )
80+ self .fields ["account" ].widget .choices = iter (account_options )
81+ # self.fields["account"] = forms.ChoiceField(
82+ # choices=account_options, label="Konto", widget=UnfoldAdminSelect2Widget()
83+ # )
7484
7585
7686class TransactionUploadForm (forms .Form ):
7787 file = forms .FileField (
7888 label = "Zahlungsdatei" ,
7989 required = False ,
80- widget = UnfoldAdminFileFieldWidget (),
81- help_text = "camt.053 oder camt.054 (XML) oder ZIP-Datei mit mehreren XML-Dateien" ,
90+ # widget=UnfoldAdminFileFieldWidget(),
91+ # help_text="camt.053 oder camt.054 (XML) oder ZIP-Datei mit mehreren XML-Dateien",
8292 )
8393
8494 def __init__ (self , * args , ** kwargs ):
8595 super ().__init__ (* args , ** kwargs )
8696 # Add Crispy Forms helper for Unfold styling
87- self .helper = FormHelper ()
88- self .helper .form_tag = False # Form tag handled in template
89- self .helper .form_class = ""
90- self .helper .layout = Layout (
91- Div ("file" , css_class = "mb-4" ),
92- )
97+ # self.helper = FormHelper()
98+ # self.helper.form_tag = False # Form tag handled in template
99+ # self.helper.form_class = ""
100+ # self.helper.layout = Layout(
101+ # Div("file", css_class="mb-4"),
102+ # )
93103
94104
95105class AccountEditForm (forms .ModelForm ):
@@ -107,9 +117,13 @@ def __init__(self, *args, **kwargs):
107117 owner_options .append (("c_%s" % c .id , str (c )))
108118 for a in Address .objects .filter (active = True ).exclude (user = None ):
109119 owner_options .append (("a_%s" % a .id , str (a )))
110- self .fields ["owner" ] = forms .ChoiceField (
111- choices = owner_options , label = "Verknüpft mit" , widget = UnfoldAdminSelect2Widget ()
120+ self .fields ["owner" ] = select2 . fields .ChoiceField (
121+ choices = owner_options , label = "Verknüpft mit"
112122 )
123+ self .fields ["owner" ].widget .choices = iter (owner_options )
124+ # self.fields["owner"] = forms.ChoiceField(
125+ # choices=owner_options, label="Verknüpft mit", widget=UnfoldAdminSelect2Widget()
126+ # )
113127
114128 def clean (self ):
115129 cleaned_data = super ().clean ()
@@ -133,17 +147,24 @@ class AccountFilterForm(forms.Form):
133147 search = forms .CharField (
134148 label = "Suche" ,
135149 required = False ,
136- widget = UnfoldAdminTextInputWidget (attrs = {"size" : "40" , "autofocus" : True }),
150+ # widget=UnfoldAdminTextInputWidget(attrs={"size": "40", "autofocus": True}),
151+ widget = forms .TextInput (attrs = {"size" : "40" , "autofocus" : True }),
137152 )
138153
139154
140155class RevenueReportForm (forms .Form ):
141156 start_date = forms .DateField (
142- label = "Start Datum" , widget = UnfoldAdminTextInputWidget (attrs = {"class" : "datepicker" })
157+ label = "Start Datum" ,
158+ widget = forms .TextInput (
159+ attrs = {"class" : "datepicker" },
160+ ),
161+ # widget=UnfoldAdminTextInputWidget(attrs={"class": "datepicker"}
143162 )
144163 start_time = forms .TimeField (label = "Start Zeit" )
145164 end_date = forms .DateField (
146- label = "End Datum" , widget = UnfoldAdminTextInputWidget (attrs = {"class" : "datepicker" })
165+ label = "End Datum" ,
166+ widget = forms .TextInput (attrs = {"class" : "datepicker" }),
167+ # widget=UnfoldAdminTextInputWidget(attrs={"class": "datepicker"})
147168 )
148169 end_time = forms .TimeField (label = "Start Zeit" )
149170
@@ -152,6 +173,10 @@ def __init__(self, *args, start_year=2022, **kwargs):
152173 period_options = [("all_years" , "Alle Jahre" ), ("manual" , "Manuelle Eingabe" )]
153174 for year in range (start_year , datetime .datetime .now ().year + 1 ):
154175 period_options .insert (0 , (f"year_{ year } " , f"Jahr { year } " ))
155- self .fields ["period" ] = forms .ChoiceField (
156- choices = period_options , label = "Zeitraum" , widget = UnfoldAdminSelect2Widget ()
176+ # self.fields["period"] = forms.ChoiceField(
177+ # choices=period_options, label="Zeitraum", widget=UnfoldAdminSelect2Widget()
178+ # )
179+ self .fields ["period" ] = select2 .fields .ChoiceField (
180+ choices = period_options , label = "Zeitraum"
157181 )
182+ self .fields ["period" ].widget .choices = iter (period_options )
0 commit comments