Skip to content

Commit

Permalink
show nps after survey transactionned was answered by a buyer
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Mar 8, 2024
1 parent 236b75e commit 407b7b5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@
FORM_PARTENAIRES = (
"https://docs.google.com/forms/d/e/1FAIpQLScx1k-UJ-962_rSgPJGabc327gGjFUho6ypgcZHCubuwTl7Lg/viewform"
)
TALLY_NPS_FORM_ID = env.str("TALLY_NPS_FORM_ID", "")
TALLY_BUYER_NPS_FORM_ID = env.str("TALLY_BUYER_NPS_FORM_ID", "")
TALLY_SIAE_NPS_FORM_ID = env.str("TALLY_SIAE_NPS_FORM_ID", "")
PARTNER_APPROCH_USER_ID = env.int("PARTNER_APPROCH_USER_ID", 0)


Expand Down
4 changes: 2 additions & 2 deletions lemarche/templates/tenders/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
}
</script>
{% endif %}
{% if TALLY_NPS_FORM_ID and show_nps %}
{% if nps_form_id %}
<script async type="text/javascript" src="https://tally.so/widgets/embed.js"></script>
<script type="text/javascript">
window.TallyConfig = {
"formId": "{{ TALLY_NPS_FORM_ID }}",
"formId": "{{ nps_form_id }}",
"popup": {
"width": 400,
"emoji": {
Expand Down
1 change: 0 additions & 1 deletion lemarche/utils/settings_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ def expose_settings(request):
"TYPEFORM_BESOIN_ACHAT_RECHERCHE": settings.TYPEFORM_BESOIN_ACHAT_RECHERCHE,
"TYPEFORM_GROUPEMENT_AJOUT": settings.TYPEFORM_GROUPEMENT_AJOUT,
"FORM_PARTENAIRES": settings.FORM_PARTENAIRES,
"TALLY_NPS_FORM_ID": settings.TALLY_NPS_FORM_ID,
"MTCAPTCHA_PUBLIC_KEY": settings.MTCAPTCHA_PUBLIC_KEY,
}
4 changes: 2 additions & 2 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ def test_update_tender_stats_on_tender_survey_transactioned_answer_true(self):
url, data={"survey_transactioned_amount": 1000, "survey_transactioned_feedback": "Feedback"}, follow=True
)
self.assertEqual(response.status_code, 200) # redirect
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + "?nps=true")
self.assertContains(response, "Merci pour votre réponse")
self.assertTrue(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertEqual(Tender.objects.get(id=self.tender.id).survey_transactioned_amount, 1000)
Expand All @@ -1804,7 +1804,7 @@ def test_update_tender_stats_on_tender_survey_transactioned_answer_false(self):
# fill in form
response = self.client.post(url, data={"survey_transactioned_feedback": "Feedback"}, follow=True)
self.assertEqual(response.status_code, 200) # redirect
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + "?nps=true")
self.assertContains(response, "Merci pour votre réponse")
self.assertFalse(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertIsNone(Tender.objects.get(id=self.tender.id).survey_transactioned_amount)
Expand Down
11 changes: 8 additions & 3 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ def get_context_data(self, **kwargs):
).exists()
)
if show_nps:
context["show_nps"] = True
context["nps_form_id"] = settings.TALLY_SIAE_NPS_FORM_ID
elif user.kind == User.KIND_BUYER:
if show_nps:
context["nps_form_id"] = settings.TALLY_BUYER_NPS_FORM_ID
elif user.kind == User.KIND_PARTNER:
context["user_partner_can_display_tender_contact_details"] = user.can_display_tender_contact_details
else:
Expand Down Expand Up @@ -646,10 +649,12 @@ def get_form_kwargs(self):
def form_valid(self, form):
super().form_valid(form)
messages.add_message(self.request, messages.SUCCESS, self.get_success_message())
return HttpResponseRedirect(self.get_success_url())
return HttpResponseRedirect(self.get_success_url(survey_was_answered=True))

def get_success_url(self):
def get_success_url(self, survey_was_answered=None):
success_url = reverse_lazy("tenders:detail", args=[self.kwargs.get("slug")])
if survey_was_answered:
success_url += "?nps=true"
return success_url

def get_success_message(self, already_answered=False):
Expand Down

0 comments on commit 407b7b5

Please sign in to comment.