Skip to content

Commit

Permalink
Envoyer message depuis la page de validation de demande #619
Browse files Browse the repository at this point in the history
  • Loading branch information
liviaribeiro authored Apr 14, 2022
2 parents 41e7a2a + 62b8665 commit 9556812
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
12 changes: 11 additions & 1 deletion aidants_connect_habilitation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +29,7 @@
Manager,
OrganisationRequest,
PersonWithResponsibilities,
RequestMessage,
)
from aidants_connect_web.models import OrganisationType

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions aidants_connect_habilitation/templates/validation_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,29 @@ <h2>Récapitulatif de la demande</h2>
Il est possible de les modifier si besoin.
</p>
{% include "_display_org_request.html" with organisation=organisation show_all_buttons=True %}
<!--
<h3>Information complémentaire</h3>
<form method="post">
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-md-8">
<div class="shadowed">
<h4 class="h3">Une question ? Une précision ?</h4>
<p class="more-info-messages">Si vous souhaitez ajouter une précision ou nous poser une question, c’est ici que ça se passe ! Saisissez votre message ci-dessous, il nous sera envoyé avec votre demande.</p>
<div class="fr-grid-row">
<div class="fr-col-4">
Votre message
</div>
<label class="fr-col-4" for="{{ form.content.id_for_label }}">Votre message</label>
<div class="fr-col-8">
Message box
{% csrf_token %}
{{ form.message_content }}
</div>
</div>
</div>
</div>
</div>
-->
<h3>Validation de la demande</h3>
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-md-8">
<div class="shadowed">
<h4 class="h2">Modalités d'utilisation</h4>
<form method="post">
{% csrf_token %}

{{ form.non_field_errors }}
{% checkbox_fr_grid_row form.cgu %}
{% checkbox_fr_grid_row form.dpo %}
Expand All @@ -53,10 +50,10 @@ <h4 class="h2">Modalités d'utilisation</h4>
</a>
<button class="primary" type="submit">Soumettre la demande</button>
</div>
</form>
</div>
</div>
</div>
</form>
{% include "_more-info.html" %}
</div>{# fr-container #}
{% endblock %}
4 changes: 4 additions & 0 deletions aidants_connect_habilitation/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.test import TestCase

from aidants_connect.common.constants import (
MessageStakeholders,
RequestOriginConstants,
RequestStatusConstants,
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion aidants_connect_habilitation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 9556812

Please sign in to comment.