summaryrefslogtreecommitdiffstats
path: root/engagements/forms.py
blob: 253289205a88c7285db5f0b150410e8180ced09f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from django import forms
from django.forms.widgets import HiddenInput

from .models import Engagement, EngagementEffort


# TODO - need to handle errors correctly in this form and in the template


class EngagementEffortReportingCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['is_planned'].widget.attrs.update({"class": "select-lg"})
        # for field in self.fields.values():
        #     field.widget.attrs['class'] = 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'

    class Meta:
        model = EngagementEffort
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording."),
            "officers": ("Include yourself here but you can also add effort for your colleagues.")
        }
        fields = [
            'is_planned',
            'proposed_start_date',
            'proposed_end_date',
            'officers',
            'notes',
        ]
        widgets = {
            # 'is_planned': forms.Select(
            #     choices=(
            #         (True, "YES"),
            #         (False, "NO"),
            #     ),
            #     attrs={'class': 'select-lg w-full max-w-xs'}
            # ),
            'proposed_start_date': forms.DateTimeInput(
                attrs={
                    'type': 'datetime-local',
                    'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'
                },
                format='j M y H:i',
            ),
            'proposed_end_date': forms.DateTimeInput(
                attrs={
                    'type': 'datetime-local',
                    'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'
                },
                format='j M y H:i',
            ),
            'officers': forms.SelectMultiple(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
            'notes': forms.Textarea(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50', 'rows': 3}),
        }


class EngagementEffortRegulationCreateForm(forms.ModelForm):

    class Meta:
        model = EngagementEffort
        fields = [
            "is_planned",
            "proposed_start_date",
            "proposed_end_date",
            "officers",
            "sub_instruments",
            "notes",
        ]
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording.")
        }
        widgets = {
            "proposed_start_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
            "proposed_end_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
        }


class EngagementEffortPlanningCreateForm(forms.ModelForm):

    class Meta:
        model = EngagementEffort
        fields = [
            "is_planned",
            "proposed_start_date",
            "proposed_end_date",
            "officers",
            "notes",
        ]
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording.")
        }
        widgets = {
            "proposed_start_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
            "proposed_end_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
        }


class EngagementEffortTravelCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['is_planned'].widget.attrs.update({"class": "select-lg"})
        for field in self.fields.values():
            field.widget.attrs['class'] = 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'

    class Meta:
        model = EngagementEffort
        fields = ["is_planned", "proposed_start_date", "proposed_end_date", "officers"]
        widgets = {
            "is_planned": forms.Select(choices=((True, "YES"), (False, "NO")), attrs={"class": "select select-bordered w-full max-w-xs"}),
            "proposed_start_date": forms.DateTimeInput(attrs={"type": "datetime-local"}),
            "proposed_end_date": forms.DateTimeInput(attrs={"type": "datetime-local"}),
        }
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording.")
        }


class EngagementEffortCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['engagement'].widget = HiddenInput()
        self.fields['effort_type'].widget = HiddenInput()
        if kwargs.get("initial"):
            if not kwargs["initial"]["effort_type"] == "REGULATION":
                self.fields["sub_instruments"].widget = HiddenInput()

        # Apply Tailwind classes to all visible fields
        # for field in self.visible_fields():
        #     field.widget.attrs['class'] = 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'

    class Meta:
        model = EngagementEffort
        fields = "__all__"
        widgets = {
            # "is_planned": forms.Select(
            #     choices=(
            #         (True, "YES"),
            #         (False, "NO"),
            #     ),
            #     attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}
            # ),
            "proposed_start_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                    "class": "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
                },
                format="j M y H:i",
            ),
            "proposed_end_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                    "class": "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
                },
                format="j M y H:i",
            ),
            "effort_type": forms.Select(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
            "officers": forms.SelectMultiple(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
            "sub_instruments": forms.SelectMultiple(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
        }


class EngagementCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        try:
            self.fields["engagement_type"].queryset = kwargs["initial"]["engagement_type"]
        except KeyError:
            pass

    class Meta:
        model = Engagement
        fields = [
            "proposed_start_date",
            "proposed_end_date",
            "engagement_type",
            "external_party",
            "officers",
        ]
        labels = {
            "officers": "Inspectors",
        }
        help_texts = {
            "proposed_start_date": "<small><em>YYYY-MM-DD</em></small>",
            "proposed_end_date": "<small><em>YYYY-MM-DD</em></small>",
        }
        widgets = {
            "proposed_start_date": forms.DateInput(attrs={"type": "date"}),
            "proposed_end_date": forms.DateInput(attrs={"type": "date"}),
            "engagement_type": forms.Select(),
            "officers": forms.SelectMultiple(),
        }