mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
redirect from address_line_n to address textarea page
if someone starts a new one-off flow they'll get taken to the address page. However, if someone hits the back button, they'll cycle backwards through placeholders and will end up on the individual line pages. Lets redirect them to the correct place. We'll additionally need to reconstruct the address block from the various session variables that may or may not be populated
This commit is contained in:
@@ -335,6 +335,18 @@ def get_notification_check_endpoint(service_id, template):
|
||||
))
|
||||
|
||||
|
||||
def get_letter_address_from_session():
|
||||
"""
|
||||
Takes non-blank-string address values out of the placeholders, and returns a multi line string
|
||||
"""
|
||||
keys = [f'address line {i}' for i in range(1, 7)] + ['postcode']
|
||||
return '\n'.join([
|
||||
session['placeholders'][key]
|
||||
for key in keys
|
||||
if session['placeholders'].get(key)
|
||||
])
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/send/<uuid:template_id>/one-off/address",
|
||||
methods=['GET', 'POST']
|
||||
@@ -364,7 +376,9 @@ def send_one_off_letter_address(service_id, template_id):
|
||||
sms_sender=None
|
||||
)
|
||||
|
||||
form = LetterAddressForm()
|
||||
current_session_address = get_letter_address_from_session()
|
||||
|
||||
form = LetterAddressForm(address=current_session_address)
|
||||
|
||||
if form.validate_on_submit():
|
||||
session['placeholders'].update(form.as_address_lines_1_to_7_with_postcode)
|
||||
@@ -467,6 +481,10 @@ def send_test_step(service_id, template_id, step_index):
|
||||
template_id=template_id,
|
||||
))
|
||||
|
||||
# if we're in a letter, we should show address block rather than "address line #" or "postcode"
|
||||
if db_template['template_type'] == 'letter' and current_placeholder in first_column_headings['letter']:
|
||||
return redirect(url_for('.send_one_off_letter_address', service_id=service_id, template_id=template_id))
|
||||
|
||||
optional_placeholder = (current_placeholder in optional_address_columns)
|
||||
form = get_placeholder_form_instance(
|
||||
current_placeholder,
|
||||
|
||||
Reference in New Issue
Block a user