Skip to content

Commit

Permalink
Merge pull request #400 from UKGovernmentBEIS/develop
Browse files Browse the repository at this point in the history
Dev -> Staging
  • Loading branch information
Glenn-Clarke authored Nov 18, 2024
2 parents ad6e72f + 33bfdcf commit 7f034d4
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 207 deletions.
3 changes: 2 additions & 1 deletion help_to_heat/frontdoor/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@

loft_insulation_field = "loft_insulation"
loft_insulation_field_more_than_threshold = "I have more than 100mm of loft insulation"
loft_insulation_field_less_than_threshold = "I have up to 100mm of loft insulation"
loft_insulation_field_less_than_threshold = "I have less than or equal to 100mm of loft insulation"
loft_insulation_field_no_insulation = "I have no loft insulation"
loft_insulation_field_dont_know = field_dont_know
loft_insulation_field_no_loft = "No loft"

Expand Down
11 changes: 11 additions & 0 deletions help_to_heat/frontdoor/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
loft_field,
loft_field_no,
loft_insulation_field,
loft_insulation_field_less_than_threshold,
loft_insulation_field_no_insulation,
loft_insulation_field_no_loft,
park_home_main_residence_field,
property_subtype_field,
Expand Down Expand Up @@ -250,6 +252,13 @@ def create_referral(self, session_id):
given_answers[loft_access_field] = loft_access_field_no_loft
given_answers[loft_insulation_field] = loft_insulation_field_no_loft

# Users are given the option to select "no insulation" to improve question usability
# This and "below threshold" are functionally identical from the supplier point of view.
# They will be combined before the suppliers see it to improve supplier usability
loft_insulation = given_answers.get(loft_insulation_field)
if loft_insulation == given_answers.get(loft_insulation_field_no_insulation):
given_answers[loft_insulation_field] = loft_insulation_field_less_than_threshold

# ensure not found EPCs are displayed as such
# this will normally be set as an answer on pressing submit on 'address' page
# though this is not guaranteed, ie if user presses to enter manually
Expand Down Expand Up @@ -597,6 +606,8 @@ def get_epc_scotland(self, uprn):
def get_address_and_epc_lmk(self, building_name_or_number, postcode):
epc_api = EPCApi()
data = epc_api.search_epc_details(building_name_or_number, postcode)
if data is None:
return []
address_and_epc_details = data["rows"]
return address_and_epc_details

Expand Down
22 changes: 15 additions & 7 deletions help_to_heat/frontdoor/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
epc_rating_field,
epc_select_manual_page,
epc_select_page,
field_dont_know,
field_no,
field_yes,
household_income_field,
Expand All @@ -63,6 +62,7 @@
loft_insulation_field_dont_know,
loft_insulation_field_less_than_threshold,
loft_insulation_field_more_than_threshold,
loft_insulation_field_no_insulation,
loft_insulation_field_no_loft,
loft_insulation_page,
loft_page,
Expand Down Expand Up @@ -105,6 +105,7 @@
schemes_page,
shell_warning_page,
shell_warning_page_field,
success_page,
summary_page,
supplier_field,
supplier_field_british_gas,
Expand Down Expand Up @@ -201,10 +202,16 @@
# which pages should ignore routing checks
# the code will not check if the user's route allows them to see these pages
# a prev page url should be provided to allow the back link to work
# or, if the page does not allow the user to go back, it may not be needed to calculate previous page
# this means the page can be seen without any routing checks being run
# if this is desired, set prev_page to the below constant
no_back_button_on_page = "no-back-button-on-page"

routing_overrides = {
address_manual_page: {"prev_page": address_page},
epc_select_manual_page: {"prev_page": epc_select_page},
address_select_manual_page: {"prev_page": address_select_page},
success_page: {"prev_page": no_back_button_on_page},
}

# which change page to send back to
Expand Down Expand Up @@ -339,10 +346,6 @@
"value": field_no,
"label": _("No"),
},
{
"value": field_dont_know,
"label": _("I do not know"),
},
)
epc_validation_options_map = epc_display_options_map + (
{
Expand Down Expand Up @@ -478,7 +481,8 @@
},
loft_insulation_field: {
loft_insulation_field_more_than_threshold: _("I have more than 100mm of loft insulation"),
loft_insulation_field_less_than_threshold: _("I have up to 100mm of loft insulation"),
loft_insulation_field_less_than_threshold: _("I have less than or equal to 100mm of loft insulation"),
loft_insulation_field_no_insulation: _("I have no loft insulation"),
loft_insulation_field_dont_know: _("I do not know"),
loft_insulation_field_no_loft: _("No loft"),
},
Expand Down Expand Up @@ -697,7 +701,11 @@
},
{
"value": loft_insulation_field_less_than_threshold,
"label": _("I have up to 100mm of loft insulation"),
"label": _("I have less than or equal to 100mm of loft insulation"),
},
{
"value": loft_insulation_field_no_insulation,
"label": _("I have no loft insulation"),
},
{
"value": loft_insulation_field_dont_know,
Expand Down
51 changes: 39 additions & 12 deletions help_to_heat/frontdoor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
from .routing import CouldNotCalculateJourneyException, calculate_journey
from .routing.backwards_routing import get_prev_page
from .routing.forwards_routing import get_next_page
from .schemas import no_back_button_on_page
from .session_handlers.duplicate_referral_checker import (
DuplicateReferralChecker,
)
Expand Down Expand Up @@ -485,6 +486,9 @@ def build_extra_context(self, request, session_id, page_name, data, is_change_pa
Build any additional data to be added to the context.
This will be available to use in the template html file.
data will be the user submitted data for this page.
if you need access to other page's answers, call interface.api.session.get_session(session_id)
"""
return {}

Expand All @@ -496,7 +500,8 @@ def save_get_data(self, data, session_id, page_name):
For instance, saving tracking data when a user loads the page
data will be the user submitted data for this page
data will be the user submitted data for this page.
if you need access to other page's answers, call interface.api.session.get_session(session_id)
"""
return data

Expand All @@ -506,7 +511,8 @@ def save_post_data(self, data, session_id, page_name):
For instance, checking and storing whether the UPRN is duplicate
data will be the user submitted data for this page
data will be the user submitted data for this page.
if you need access to other page's answers, call interface.api.session.get_session(session_id)
The returned data object will be used to decide which page to send to
"""
Expand Down Expand Up @@ -556,7 +562,15 @@ def _get_prev_page_url(self, request, session_id, page_name, is_change_page):
)

if page_name in schemas.routing_overrides:
return page_name_to_url(session_id, schemas.routing_overrides[page_name]["prev_page"])
prev_page = schemas.routing_overrides[page_name]["prev_page"]

# the page is assumed to not have a back button so this should not be shown to the user
# in case it ever does, provide a fallback so the user does not get into an invalid state
# in this case, leave them on the page they are currently on
if prev_page == no_back_button_on_page:
return page_name_to_url(session_id, page_name)

return page_name_to_url(session_id, prev_page)

return page_name_to_url(session_id, get_prev_page(page_name, answers))

Expand Down Expand Up @@ -603,14 +617,21 @@ def build_extra_context(self, request, session_id, page_name, data, is_change_pa

def save_post_data(self, data, session_id, page_name):
reset_epc_details(session_id)
country = data.get(country_field)
session_data = interface.api.session.get_session(session_id)
country = session_data.get(country_field)
building_name_or_number = data.get(address_building_name_or_number_field)
postcode = data.get(address_postcode_field)
try:
data[address_choice_field] = address_choice_field_write_address
if country != country_field_scotland:
address_and_lmk_details = interface.api.epc.get_address_and_epc_lmk(building_name_or_number, postcode)
data[address_all_address_and_lmk_details_field] = address_and_lmk_details

if len(address_and_lmk_details) > 0:
data[address_all_address_and_lmk_details_field] = address_and_lmk_details
data[address_choice_field] = address_choice_field_write_address
else:
data[address_choice_field] = address_choice_field_epc_api_fail
else:
data[address_choice_field] = address_choice_field_write_address
except Exception as e: # noqa: B902
logger.exception(f"An error occurred: {e}")
data[address_choice_field] = address_choice_field_epc_api_fail
Expand Down Expand Up @@ -866,16 +887,19 @@ def build_extra_context(self, request, session_id, page_name, data, is_change_pa
gds_epc_date = None

current_month, next_month = utils.get_current_and_next_month_names(month_names)
current_quarter_month, next_quarter_month = utils.get_current_and_next_quarter_month_names(month_names)
(
scottish_epc_cutoff_month,
next_scottish_dump_month,
) = utils.get_current_scottish_epc_cutoff_and_next_dump_month_names(month_names)

context = {
"epc_rating": epc_band.upper() if epc_band else "",
"gds_epc_date": gds_epc_date,
"epc_date": epc_date,
"current_month": current_month,
"next_month": next_month,
"current_quarter_month": current_quarter_month,
"next_quarter_month": next_quarter_month,
"scottish_epc_cutoff_month": scottish_epc_cutoff_month,
"next_scottish_dump_month": next_scottish_dump_month,
"property_type": property_type,
"epc_display_options": schemas.epc_display_options_map,
"address": address,
Expand All @@ -900,15 +924,18 @@ def build_extra_context(self, request, session_id, page_name, data, is_change_pa
country = session_data.get(country_field)

current_month, next_month = utils.get_current_and_next_month_names(month_names)
current_quarter_month, next_quarter_month = utils.get_current_and_next_quarter_month_names(month_names)
(
scottish_epc_cutoff_month,
next_scottish_dump_month,
) = utils.get_current_scottish_epc_cutoff_and_next_dump_month_names(month_names)

show_month_wording = country in [country_field_england, country_field_wales]

return {
"current_month": current_month,
"next_month": next_month,
"current_quarter_month": current_quarter_month,
"next_quarter_month": next_quarter_month,
"scottish_epc_cutoff_month": scottish_epc_cutoff_month,
"next_scottish_dump_month": next_scottish_dump_month,
"show_month_wording": show_month_wording,
}

Expand Down
Binary file modified help_to_heat/locale/cy/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 7f034d4

Please sign in to comment.