Skip to content

Commit

Permalink
buyer nps must be in transactionned survey
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Mar 8, 2024
1 parent 407b7b5 commit 67a2402
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
22 changes: 22 additions & 0 deletions lemarche/templates/tenders/_detail_nps_tally_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script async type="text/javascript" src="https://tally.so/widgets/embed.js"></script>
<script type="text/javascript">
window.TallyConfig = {
"formId": "{{ nps_form_id }}",
"popup": {
"width": 400,
"emoji": {
"text": "👋",
"animation": "wave"
},
"open": {
"trigger": "time",
"ms": 2000
},
// "showOnce": true, // show the popup only once to the same visitor (even if he didn't submit)
"doNotShowAfterSubmit": true, // after the visitor submits the form, don't show the popup again
"autoClose": 0, // automatically hide the popup after the form is submitted. optionally set a delay in seconds.
"hideTitle": true,
"layout": "modal" // display in the center instead of bottom right corner
},
};
</script>
23 changes: 1 addition & 22 deletions lemarche/templates/tenders/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,6 @@
</script>
{% endif %}
{% if nps_form_id %}
<script async type="text/javascript" src="https://tally.so/widgets/embed.js"></script>
<script type="text/javascript">
window.TallyConfig = {
"formId": "{{ nps_form_id }}",
"popup": {
"width": 400,
"emoji": {
"text": "👋",
"animation": "wave"
},
"open": {
"trigger": "time",
"ms": 2000
},
// "showOnce": true, // show the popup only once to the same visitor (even if he didn't submit)
"doNotShowAfterSubmit": true, // after the visitor submits the form, don't show the popup again
"autoClose": 0, // automatically hide the popup after the form is submitted. optionally set a delay in seconds.
"hideTitle": true,
"layout": "modal" // display in the center instead of bottom right corner
},
};
</script>
{% include "tenders/_detail_nps_tally_form.html" %}
{% endif %}
{% endblock %}
6 changes: 6 additions & 0 deletions lemarche/templates/tenders/survey_transactioned_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ <h1 class="h1 mb-3 mb-lg-5">
</div>
</section>
{% endblock %}

{% block extra_js %}
{% if nps_form_id %}
{% include "tenders/_detail_nps_tally_form.html" %}
{% endif %}
{% endblock %}
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}) + "?nps=true")
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
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}) + "?nps=true")
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
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
10 changes: 3 additions & 7 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ def get_context_data(self, **kwargs):
)
if show_nps:
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 @@ -639,6 +636,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["tender"] = self.object
context["parent_title"] = TITLE_DETAIL_PAGE_OTHERS
context["nps_form_id"] = settings.TALLY_BUYER_NPS_FORM_ID
return context

def get_form_kwargs(self):
Expand All @@ -649,12 +647,10 @@ 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(survey_was_answered=True))
return HttpResponseRedirect(self.get_success_url())

def get_success_url(self, survey_was_answered=None):
def get_success_url(self):
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 67a2402

Please sign in to comment.