Skip to content

Commit

Permalink
added logic for handling post requests when the user is referred from…
Browse files Browse the repository at this point in the history
… the summary page
  • Loading branch information
jenriordan committed Feb 20, 2024
1 parent 73366ac commit 204c22b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
38 changes: 21 additions & 17 deletions report_a_breach/base_classes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,28 @@ def get_context_data(self, form, **kwargs):
context.update(custom_getter(form))
return context

def process_step(self, form):
def process_step(self, form, **kwargs):
if custom_getter := getattr(self, f"process_{self.steps.current}_step", None):
return custom_getter(form)
return super().process_step(form)

def post(self, request, **kwargs):
# TODO: this code isn't reachable if the user selects change on the summary page.
# TODO: need further debug - possible to add to a process step
# TODO: investigate wizard forms redirect methods?
for key, value in request.POST.items():
print(key, value)
if value == "summary":
kwargs["redirect_to"] = "summary"
print(kwargs)
return super().post(request, **kwargs)
for key, value in kwargs.items():
print(f"kwargs {key, value}")
if key == "redirect_to":
print("attempting redirect to summary page")
return reverse("summary")
return super().post(request, **kwargs)
def post(self, *args, **kwargs):
full_path = self.request.get_full_path()
session = self.request.session
step = "summary"

# the user is directed here if they selected the change link on the summary page
if "redirect=true" in full_path:
if "email" in full_path:
session["redirect"] = step
return super().post(*args, **kwargs)
return self.render_goto_step(step, **kwargs)

elif "verify" in full_path:
return (
self.render_goto_step(step, **kwargs)
if session.get("redirect")
else super().post(*args, **kwargs)
)

return super().post(*args, **kwargs)
6 changes: 3 additions & 3 deletions report_a_breach/templates/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2 class="govuk-summary-card__title">Your details</h2>
{{ reporter_email_address }}
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="/report_a_breach/email">Change<span class="govuk-visually-hidden"> email (Your details)</span></a>
<a class="govuk-link" href="/report_a_breach/email?redirect=true">Change<span class="govuk-visually-hidden"> email (Your details)</span></a>
</dd>
</div>
<div class="govuk-summary-list__row">
Expand All @@ -33,7 +33,7 @@ <h2 class="govuk-summary-card__title">Your details</h2>
{{ reporter_full_name }}
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="/report_a_breach/name">Change<span class="govuk-visually-hidden"> full name (Your details)</span></a>
<a class="govuk-link" href="/report_a_breach/name?redirect=true">Change<span class="govuk-visually-hidden"> full name (Your details)</span></a>
</dd>
</div>
<div class="govuk-summary-list__row">
Expand All @@ -45,7 +45,7 @@ <h2 class="govuk-summary-card__title">Your details</h2>
{{ company_relationship }}
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="/report_a_breach/start">Change<span class="govuk-visually-hidden"> professional relationship with the organisation (Your details)</span></a>
<a class="govuk-link" href="/report_a_breach/start?redirect=true">Change<span class="govuk-visually-hidden"> professional relationship with the organisation (Your details)</span></a>
</dd>
</div>
</dl>
Expand Down

0 comments on commit 204c22b

Please sign in to comment.