diff --git a/network-api/networkapi/donate/pagemodels/help_page.py b/network-api/networkapi/donate/pagemodels/help_page.py index 7ddf39f0e09..c4a32ed2f52 100644 --- a/network-api/networkapi/donate/pagemodels/help_page.py +++ b/network-api/networkapi/donate/pagemodels/help_page.py @@ -1,3 +1,5 @@ +from urllib.parse import urlencode + from wagtail.admin.panels import FieldPanel from wagtail.fields import StreamField from wagtail.models import Page @@ -44,3 +46,16 @@ class DonateHelpPage(BaseDonationPage): TranslatableField("notice"), TranslatableField("body"), ] + + def get_context(self, request): + context = super().get_context(request) + context["thank_you_url"] = self.get_thank_you_url(request) + context["show_formassembly_thank_you"] = context["request"].GET.get("thank_you") == "true" + return context + + def get_thank_you_url(self, request): + base_url = self.get_full_url() + existing_params = request.GET.dict() + existing_params["thank_you"] = "true" + thank_you_url = base_url + "?" + urlencode(existing_params) + return thank_you_url diff --git a/network-api/networkapi/donate/tests/test_help_page.py b/network-api/networkapi/donate/tests/test_help_page.py index a38ff94a279..02835454aad 100644 --- a/network-api/networkapi/donate/tests/test_help_page.py +++ b/network-api/networkapi/donate/tests/test_help_page.py @@ -71,3 +71,26 @@ def test_help_page_notice_field(self): Asserts that a 'notice' block was created in the 'notice' field by the factory. """ self.assertEqual(self.donate_help_page.notice[0].block_type, "notice") + + def test_thank_you_url(self): + """ + Testing that the "thank_you_url" is correctly added to the page context. + """ + page_url = self.donate_help_page.get_full_url() + response = self.client.get(page_url) + + expected_thank_you_url = page_url + "?thank_you=true" + + self.assertEqual(response.context["thank_you_url"], expected_thank_you_url) + + def test_thank_you_url_with_existing_query_params(self): + """ + Testing that the "thank_you_url" is correctly added to the page context when there + are existing query parameters. + """ + page_url = self.donate_help_page.get_full_url() + "?existing_param=value" + response = self.client.get(page_url) + + expected_thank_you_url = page_url + "&thank_you=true" + + self.assertEqual(response.context["thank_you_url"], expected_thank_you_url) diff --git a/network-api/networkapi/templates/donate/fragments/formassembly_body.html b/network-api/networkapi/templates/donate/fragments/formassembly_body.html index 597ea656643..b00987d4b75 100644 --- a/network-api/networkapi/templates/donate/fragments/formassembly_body.html +++ b/network-api/networkapi/templates/donate/fragments/formassembly_body.html @@ -11,17 +11,22 @@ 2. Run `inv format-html` in terminal -3. Add nonce="{{ csp_nonce }}" to all script tags in this file +3. Update value for "Thank You Page URL" field + - In the FormAssembly form builder, this field currently has the ID of "tfa_236". + - If this field ID changes after making changes to the form, please update the line above. + - Find the element with the same ID in the code below, and update the value to: value="{{ thank_you_url }}". -4. Get localization working again. +4 Add nonce="{{ csp_nonce }}" to all script tags in this file + +5. Get localization working again. - Localize "title" attribute and label text for all fields using {% trans %} or {% blocktrans %}. - If applicable, localize any other text on the form. For example, text within htmlContent divs. - Localize "value" attribute for - Go to formassembly_head.html and make sure everything has been updated according to the instructions. -5. Update the revision note on the next line. Revision number can be found on https://mozillafoundation.tfaforms.net/versions/index/12 +6. Update the revision note on the next line. Revision number can be found on https://mozillafoundation.tfaforms.net/versions/index/12 -The code snippet below is based on FormAssembly form revision #45 +The code snippet below is based on FormAssembly form revision #46 {% endcomment %} @@ -127,6 +132,7 @@ +