diff options
author | Matthew Lemon <y@yulqen.org> | 2024-09-10 14:35:43 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-09-10 14:35:43 +0100 |
commit | b87f2e3410cf3445a4eeb1ca16d04cc7de71c330 (patch) | |
tree | 15f57b07a46f2e37344136714d6631c887ca23d1 /engagements | |
parent | 15eceda8c762c3e3890f2c160d1c89c36a7b398b (diff) |
Test passing for form for creating EngagementStrategy
Diffstat (limited to 'engagements')
-rw-r--r-- | engagements/forms.py | 106 | ||||
-rw-r--r-- | engagements/tests/test_forms.py | 22 |
2 files changed, 83 insertions, 45 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 diff --git a/engagements/tests/test_forms.py b/engagements/tests/test_forms.py index 24077e9..851f986 100644 --- a/engagements/tests/test_forms.py +++ b/engagements/tests/test_forms.py @@ -1,8 +1,8 @@ import pytest from django.forms import DateInput, Select, SelectMultiple -from engagements.forms import EngagementCreateForm, EngagementEffortCreateForm -from engagements.models import EngagementType +from engagements.forms import EngagementCreateForm, EngagementEffortCreateForm, EngagementStrategyCreateForm +from engagements.models import EngagementType, RegulatoryCycle pytestmark = pytest.mark.django_db @@ -111,3 +111,21 @@ def test_form_engagement_type_queryset(engagement_type): def test_form_engagement_type_queryset_without_initial(): form = EngagementCreateForm() assert list(form.fields["engagement_type"].queryset) == list(EngagementType.objects.all()) + + +def test_create_engagement_strategy_form(org, user, regulatory_cycles): + sy = RegulatoryCycle.objects.get(start_date="2022-01-01") + ey = RegulatoryCycle.objects.get(start_date="2024-01-01") + form_data = { + "organisation": org, + "start_year": sy, + "end_year": ey, + "description": "Example description", + "inspector_sign_off": "2022-01-10", + "owned_by": user, + "reviewed_by": user, + "management_sign_off": "2022-02-10", + "status": "DRAFT", + } + form = EngagementStrategyCreateForm(data=form_data) + assert form.is_valid() |