diff --git a/aidants_connect_habilitation/forms.py b/aidants_connect_habilitation/forms.py index aac589ee0..3cab1bd10 100644 --- a/aidants_connect_habilitation/forms.py +++ b/aidants_connect_habilitation/forms.py @@ -17,7 +17,7 @@ from phonenumber_field.formfields import PhoneNumberField from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget -from aidants_connect.common.constants import RequestOriginConstants +from aidants_connect.common.constants import MessageStakeholders, RequestOriginConstants from aidants_connect.common.forms import ( PatchedErrorList, PatchedErrorListForm, @@ -29,6 +29,7 @@ Manager, OrganisationRequest, PersonWithResponsibilities, + RequestMessage, ) from aidants_connect_web.models import OrganisationType @@ -372,6 +373,9 @@ class ValidationForm(PatchedForm): "Aidants Connect. Le responsable Aidants Connect ainsi que les aidants " "à habiliter ne sont pas des élus.", ) + message_content = CharField( + label="Votre message", required=False, widget=Textarea(attrs={"rows": 4}) + ) def __init__(self, **kwargs): super().__init__(**kwargs) @@ -382,6 +386,12 @@ def save( self, organisation: OrganisationRequest, commit=True ) -> OrganisationRequest: organisation.prepare_request_for_ac_validation(self.cleaned_data) + if self.cleaned_data["message_content"] != "": + RequestMessage.objects.create( + organisation=organisation, + sender=MessageStakeholders.ISSUER.name, + content=self.cleaned_data["message_content"], + ) return organisation save.alters_data = True diff --git a/aidants_connect_habilitation/templates/validation_form.html b/aidants_connect_habilitation/templates/validation_form.html index 7a9c25dc2..4fce47d7f 100644 --- a/aidants_connect_habilitation/templates/validation_form.html +++ b/aidants_connect_habilitation/templates/validation_form.html @@ -15,32 +15,29 @@

Récapitulatif de la demande

Il est possible de les modifier si besoin.

{% include "_display_org_request.html" with organisation=organisation show_all_buttons=True %} -

Validation de la demande

Modalités d'utilisation

-
- {% csrf_token %} + {{ form.non_field_errors }} {% checkbox_fr_grid_row form.cgu %} {% checkbox_fr_grid_row form.dpo %} @@ -53,10 +50,10 @@

Modalités d'utilisation

-
+ {% include "_more-info.html" %} {# fr-container #} {% endblock %} diff --git a/aidants_connect_habilitation/tests/test_forms.py b/aidants_connect_habilitation/tests/test_forms.py index b50c8ceb1..1216e28fb 100644 --- a/aidants_connect_habilitation/tests/test_forms.py +++ b/aidants_connect_habilitation/tests/test_forms.py @@ -3,6 +3,7 @@ from django.test import TestCase from aidants_connect.common.constants import ( + MessageStakeholders, RequestOriginConstants, RequestStatusConstants, ) @@ -217,6 +218,7 @@ def test_form_valid_works(self): form = ValidationForm( data={name: True for name in TestValidationFormForm.names_attr} ) + form.data["message_content"] = "Bonjour" form.is_valid() orga = form.save(organisation=orga_request) @@ -227,3 +229,5 @@ def test_form_valid_works(self): self.assertTrue(getattr(orga, name)) for name in TestValidationFormForm.names_attr ] + self.assertEqual(orga.messages.all()[0].content, "Bonjour") + self.assertEqual(orga.messages.all()[0].sender, MessageStakeholders.ISSUER.name) diff --git a/aidants_connect_habilitation/views.py b/aidants_connect_habilitation/views.py index 72d3e8508..9424ea7ca 100644 --- a/aidants_connect_habilitation/views.py +++ b/aidants_connect_habilitation/views.py @@ -384,7 +384,7 @@ def get_success_url(self): def form_valid(self, form): message: RequestMessage = form.save(commit=False) - message.sender = MessageStakeholders.ISSUER.value + message.sender = MessageStakeholders.ISSUER.name message.organisation = self.organisation message.save()