summaryrefslogtreecommitdiffstats
path: root/engagements/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'engagements/forms.py')
-rw-r--r--engagements/forms.py155
1 files changed, 58 insertions, 97 deletions
diff --git a/engagements/forms.py b/engagements/forms.py
index ae01916..a1c3c44 100644
--- a/engagements/forms.py
+++ b/engagements/forms.py
@@ -1,74 +1,56 @@
-from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Field, Fieldset, Layout, Submit
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.helper = FormHelper()
- self.helper.layout = Layout(
- Fieldset(
- "This is a form",
- Field("is_planned"),
- Field("proposed_start_date", css_class="w3-input w3-border w3-round", type="date"),
- Field("proposed_end_date", css_class="w3-input w3-border w3-round"),
- "officers",
- "notes",
- ),
- Submit("submit", "Submit", css_class="w3-button w3-green"),
- )
+ 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",
- "notes",
+ 'is_planned',
+ 'proposed_start_date',
+ 'proposed_end_date',
+ 'officers',
+ 'notes',
]
- help_texts = {
- "is_planned": ("<br><small><em>To distinguish planned events from retrospective recording</em></small>")
- }
widgets = {
- "proposed_start_date": forms.DateTimeInput(
+ # 'is_planned': forms.Select(
+ # choices=(
+ # (True, "YES"),
+ # (False, "NO"),
+ # ),
+ # attrs={'class': 'select-lg w-full max-w-xs'}
+ # ),
+ 'proposed_start_date': forms.DateTimeInput(
attrs={
- "class": "w3-input w3-border w3-round",
- "type": "datetime-local",
+ '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",
+ format='j M y H:i',
),
- "proposed_end_date": forms.DateTimeInput(
+ 'proposed_end_date': forms.DateTimeInput(
attrs={
- "class": "w3-input w3-border w3-round",
- "type": "datetime-local",
+ '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",
+ 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):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.helper = FormHelper()
- self.helper.layout = Layout(
- Fieldset(
- "This is a form",
- Field("is_planned"),
- Field("proposed_start_date", css_class="w3-input w3-border w3-round", type="date"),
- Field("proposed_end_date", css_class="w3-input w3-border w3-round"),
- "sub_instruments",
- "officers",
- ),
- Submit("submit", "Submit", css_class="w3-button w3-green"),
- )
class Meta:
model = EngagementEffort
@@ -86,14 +68,12 @@ class EngagementEffortRegulationCreateForm(forms.ModelForm):
widgets = {
"proposed_start_date": forms.DateTimeInput(
attrs={
- "class": "w3-input w3-border w3-round",
"type": "datetime-local",
},
format="j M y H:i",
),
"proposed_end_date": forms.DateTimeInput(
attrs={
- "class": "w3-input w3-border w3-round",
"type": "datetime-local",
},
format="j M y H:i",
@@ -102,20 +82,6 @@ class EngagementEffortRegulationCreateForm(forms.ModelForm):
class EngagementEffortPlanningCreateForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.helper = FormHelper()
- self.helper.layout = Layout(
- Fieldset(
- "This is a form",
- Field("is_planned"),
- Field("proposed_start_date", css_class="w3-input w3-border w3-round", type="date"),
- Field("proposed_end_date", css_class="w3-input w3-border w3-round"),
- "officers",
- "notes",
- ),
- Submit("submit", "Submit", css_class="w3-button w3-green"),
- )
class Meta:
model = EngagementEffort
@@ -132,14 +98,12 @@ class EngagementEffortPlanningCreateForm(forms.ModelForm):
widgets = {
"proposed_start_date": forms.DateTimeInput(
attrs={
- "class": "w3-input w3-border w3-round",
"type": "datetime-local",
},
format="j M y H:i",
),
"proposed_end_date": forms.DateTimeInput(
attrs={
- "class": "w3-input w3-border w3-round",
"type": "datetime-local",
},
format="j M y H:i",
@@ -150,22 +114,15 @@ class EngagementEffortPlanningCreateForm(forms.ModelForm):
class EngagementEffortTravelCreateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.helper = FormHelper()
- self.helper.layout = Layout(
- Fieldset(
- "This is a form",
- Field("is_planned"),
- Field("proposed_start_date", css_class="w3-input w3-border w3-round", type="date"),
- Field("proposed_end_date", css_class="w3-input w3-border w3-round"),
- "officers",
- ),
- Submit("submit", "Submit", css_class="w3-button w3-green"),
- )
+ 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"}),
}
@@ -174,40 +131,44 @@ class EngagementEffortTravelCreateForm(forms.ModelForm):
class EngagementEffortCreateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.fields["engagement"].widget = HiddenInput()
- self.fields["effort_type"].widget = HiddenInput()
+ 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": "w3-border"},
- ),
+ # "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={"class": "w3-input w3-border w3-round", "type": "date"},
+ 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={"class": "w3-input w3-border w3-round", "type": "date"},
+ 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": "w3-select w3-border w3-round"}),
- "officers": forms.SelectMultiple(attrs={"class": "w3-select w3-border w3-round"}),
- "sub_instruments": forms.SelectMultiple(attrs={"class": "w3-select w3-border w3-round"}),
- }
- help_texts = {
- "proposed_start_date": "<small><em>YYYY-MM-DD HH:MM</em> "
- "(<strong>Please include time here</strong>)</small>",
- "proposed_end_date": "<small><em>YYYY-MM-DD HH:MM</em> "
- "(<strong>Please include time here</strong>)</small>",
+ "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'}),
}
@@ -235,8 +196,8 @@ class EngagementCreateForm(forms.ModelForm):
"proposed_end_date": "<small><em>YYYY-MM-DD</em></small>",
}
widgets = {
- "proposed_start_date": forms.DateInput(attrs={"class": "w3-input w3-border w3-round", "type": "date"}),
- "proposed_end_date": forms.DateInput(attrs={"class": "w3-input w3-border w3-round", "type": "date"}),
- "engagement_type": forms.Select(attrs={"class": "w3-select w3-input w3-border w3-round"}),
- "officers": forms.SelectMultiple(attrs={"class": "w3-input w3-border w3-round"}),
+ "proposed_start_date": forms.DateInput(attrs={"type": "date"}),
+ "proposed_end_date": forms.DateInput(attrs={"type": "date"}),
+ "engagement_type": forms.Select(),
+ "officers": forms.SelectMultiple(),
}