summaryrefslogtreecommitdiffstats
path: root/engagements/forms.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-10 14:35:43 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-10 14:35:43 +0100
commitb87f2e3410cf3445a4eeb1ca16d04cc7de71c330 (patch)
tree15f57b07a46f2e37344136714d6631c887ca23d1 /engagements/forms.py
parent15eceda8c762c3e3890f2c160d1c89c36a7b398b (diff)
Test passing for form for creating EngagementStrategy
Diffstat (limited to 'engagements/forms.py')
-rw-r--r--engagements/forms.py106
1 files changed, 63 insertions, 43 deletions
diff --git a/engagements/forms.py b/engagements/forms.py
index 0b097df..cccaf3b 100644
--- a/engagements/forms.py
+++ b/engagements/forms.py
@@ -1,17 +1,14 @@
from django import forms
-from django.forms.widgets import HiddenInput
from django.core.exceptions import ValidationError
+from django.forms.widgets import HiddenInput
-from .models import Engagement, EngagementEffort
-
-
-# TODO - need to handle errors correctly in this form and in the template
+from .models import Engagement, EngagementEffort, EngagementStrategy
class EngagementEffortReportingCreateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.fields['is_planned'].widget.attrs.update({"class": "select-lg"})
+ 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'
@@ -19,14 +16,14 @@ class EngagementEffortReportingCreateForm(forms.ModelForm):
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.")
+ "officers": ("Include yourself here but you can also add effort for your colleagues."),
}
fields = [
- 'is_planned',
- 'proposed_start_date',
- 'proposed_end_date',
- 'officers',
- 'notes',
+ "is_planned",
+ "proposed_start_date",
+ "proposed_end_date",
+ "officers",
+ "notes",
]
widgets = {
# 'is_planned': forms.Select(
@@ -36,27 +33,35 @@ class EngagementEffortReportingCreateForm(forms.ModelForm):
# ),
# attrs={'class': 'select-lg w-full max-w-xs'}
# ),
- 'proposed_start_date': forms.DateTimeInput(
+ "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'
+ "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={
- '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'
+ "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,
+ }
),
- '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 = [
@@ -67,9 +72,7 @@ class EngagementEffortRegulationCreateForm(forms.ModelForm):
"sub_instruments",
"notes",
]
- help_texts = {
- "is_planned": ("To distinguish planned events from retrospective recording.")
- }
+ help_texts = {"is_planned": ("To distinguish planned events from retrospective recording.")}
widgets = {
"proposed_start_date": forms.DateTimeInput(
attrs={
@@ -87,7 +90,6 @@ class EngagementEffortRegulationCreateForm(forms.ModelForm):
class EngagementEffortPlanningCreateForm(forms.ModelForm):
-
class Meta:
model = EngagementEffort
fields = [
@@ -97,9 +99,7 @@ class EngagementEffortPlanningCreateForm(forms.ModelForm):
"officers",
"notes",
]
- help_texts = {
- "is_planned": ("To distinguish planned events from retrospective recording.")
- }
+ help_texts = {"is_planned": ("To distinguish planned events from retrospective recording.")}
widgets = {
"proposed_start_date": forms.DateTimeInput(
attrs={
@@ -119,28 +119,30 @@ class EngagementEffortPlanningCreateForm(forms.ModelForm):
class EngagementEffortTravelCreateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.fields['is_planned'].widget.attrs.update({"class": "select-lg"})
+ 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'
+ 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"}),
+ "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.")
- }
+ 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()
+ 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()
@@ -163,20 +165,32 @@ class EngagementEffortCreateForm(forms.ModelForm):
"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"
+ "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"
+ "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'}),
+ "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"
+ }
+ ),
}
@@ -220,3 +234,9 @@ class EngagementCreateForm(forms.ModelForm):
"engagement_type": forms.Select(),
"officers": forms.SelectMultiple(),
}
+
+
+class EngagementStrategyCreateForm(forms.ModelForm):
+ class Meta:
+ fields = "__all__"
+ model = EngagementStrategy