Fixed logic for Additional Details section (bonus bug fix). Also linted

This commit is contained in:
CocoByte 2024-08-12 17:11:38 -06:00
parent 5083298aca
commit adb7a6ca19
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
3 changed files with 26 additions and 10 deletions

View file

@ -296,23 +296,29 @@ class DomainInformation(TimeStampedModel):
"""Some yes/no forms use a db field to track whether it was checked or not. """Some yes/no forms use a db field to track whether it was checked or not.
We handle that here for def save(). We handle that here for def save().
""" """
# Check if the firstname or lastname of cisa representative has any data.
# Then set the has_cisa_representative flag accordingly (so that it isn't
# "none", which indicates an incomplete form).
# This ensures that if we have prefilled data, the form is prepopulated # This ensures that if we have prefilled data, the form is prepopulated
if self.cisa_representative_first_name is not None or self.cisa_representative_last_name is not None: if self.cisa_representative_first_name is not None or self.cisa_representative_last_name is not None:
self.has_cisa_representative = ( self.has_cisa_representative = (
self.cisa_representative_first_name != "" and self.cisa_representative_last_name != "" self.cisa_representative_first_name != "" and self.cisa_representative_last_name != ""
) )
# This check is required to ensure that the form doesn't start out checked # Check for blank data and update has_cisa_representative accordingly (if it isn't None)
if self.has_cisa_representative is not None: if self.has_cisa_representative is not None:
self.has_cisa_representative = ( self.has_cisa_representative = (
self.cisa_representative_first_name != "" and self.cisa_representative_first_name is not None self.cisa_representative_first_name != "" and self.cisa_representative_first_name is not None
) and (self.cisa_representative_last_name != "" and self.cisa_representative_last_name is not None) ) and (self.cisa_representative_last_name != "" and self.cisa_representative_last_name is not None)
# Check if anything_else has any data.
# Then set the has_anything_else_text flag accordingly (so that it isn't
# "none", which indicates an incomplete form).
# This ensures that if we have prefilled data, the form is prepopulated # This ensures that if we have prefilled data, the form is prepopulated
if self.anything_else is not None: if self.anything_else is not None:
self.has_anything_else_text = self.anything_else != "" self.has_anything_else_text = self.anything_else != ""
# This check is required to ensure that the form doesn't start out checked. # Check for blank data and update has_anything_else_text accordingly (if it isn't None)
if self.has_anything_else_text is not None: if self.has_anything_else_text is not None:
self.has_anything_else_text = self.anything_else != "" and self.anything_else is not None self.has_anything_else_text = self.anything_else != "" and self.anything_else is not None

View file

@ -645,23 +645,29 @@ class DomainRequest(TimeStampedModel):
"""Some yes/no forms use a db field to track whether it was checked or not. """Some yes/no forms use a db field to track whether it was checked or not.
We handle that here for def save(). We handle that here for def save().
""" """
# Check if the firstname or lastname of cisa representative has any data.
# Then set the has_cisa_representative flag accordingly (so that it isn't
# "none", which indicates an incomplete form).
# This ensures that if we have prefilled data, the form is prepopulated # This ensures that if we have prefilled data, the form is prepopulated
if self.cisa_representative_first_name is not None or self.cisa_representative_last_name is not None: if self.cisa_representative_first_name is not None or self.cisa_representative_last_name is not None:
self.has_cisa_representative = ( self.has_cisa_representative = (
self.cisa_representative_first_name != "" and self.cisa_representative_last_name != "" self.cisa_representative_first_name != "" and self.cisa_representative_last_name != ""
) )
# This check is required to ensure that the form doesn't start out checked # Check for blank data and update has_cisa_representative accordingly (if it isn't None)
if self.has_cisa_representative is not None: if self.has_cisa_representative is not None:
self.has_cisa_representative = ( self.has_cisa_representative = (
self.cisa_representative_first_name != "" and self.cisa_representative_first_name is not None self.cisa_representative_first_name != "" and self.cisa_representative_first_name is not None
) and (self.cisa_representative_last_name != "" and self.cisa_representative_last_name is not None) ) and (self.cisa_representative_last_name != "" and self.cisa_representative_last_name is not None)
# Check if anything_else has any data.
# Then set the has_anything_else_text flag accordingly (so that it isn't
# "none", which indicates an incomplete form).
# This ensures that if we have prefilled data, the form is prepopulated # This ensures that if we have prefilled data, the form is prepopulated
if self.anything_else is not None: if self.anything_else is not None:
self.has_anything_else_text = self.anything_else != "" self.has_anything_else_text = self.anything_else != ""
# This check is required to ensure that the form doesn't start out checked. # Check for blank data and update has_anything_else_text accordingly (if it isn't None)
if self.has_anything_else_text is not None: if self.has_anything_else_text is not None:
self.has_anything_else_text = self.anything_else != "" and self.anything_else is not None self.has_anything_else_text = self.anything_else != "" and self.anything_else is not None

View file

@ -217,11 +217,11 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
if current_url == self.EDIT_URL_NAME and "id" in kwargs: if current_url == self.EDIT_URL_NAME and "id" in kwargs:
del self.storage del self.storage
self.storage["domain_request_id"] = kwargs["id"] self.storage["domain_request_id"] = kwargs["id"]
# refresh step_history to ensure we don't erroneously unlock unfinished # refresh step_history to ensure we don't erroneously unlock unfinished
# steps just because we visited it # steps just because we visited it
self.storage["step_history"] = self.db_check_for_unlocking_steps() self.storage["step_history"] = self.db_check_for_unlocking_steps()
# if accessing this class directly, redirect to either to an acknowledgement # if accessing this class directly, redirect to either to an acknowledgement
# page or to the first step in the processes (if an edit rather than a new request); # page or to the first step in the processes (if an edit rather than a new request);
# subclasseswill NOT be redirected. The purpose of this is to allow code to # subclasseswill NOT be redirected. The purpose of this is to allow code to
@ -348,12 +348,12 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
# The way this works is as follows: # The way this works is as follows:
# Each step is assigned a true/false value to determine if it is # Each step is assigned a true/false value to determine if it is
# "unlocked" or not. This dictionary of values is looped through # "unlocked" or not. This dictionary of values is looped through
# at the end of this function and any step with a "true" value is # at the end of this function and any step with a "true" value is
# added to a simple array that is returned at the end of this function. # added to a simple array that is returned at the end of this function.
# This array is eventually passed to the frontend context (eg. domain_request_sidebar.html), # This array is eventually passed to the frontend context (eg. domain_request_sidebar.html),
# and is used to determine how steps appear in the side nav. # and is used to determine how steps appear in the side nav.
# It is worth noting that any step assigned "false" here will be EXCLUDED # It is worth noting that any step assigned "false" here will be EXCLUDED
# from the list of "unlocked" steps. # from the list of "unlocked" steps.
history_dict = { history_dict = {
"generic_org_type": self.domain_request.generic_org_type is not None, "generic_org_type": self.domain_request.generic_org_type is not None,
@ -369,7 +369,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
or self.domain_request.zipcode is not None or self.domain_request.zipcode is not None
or self.domain_request.urbanization is not None or self.domain_request.urbanization is not None
), ),
"about_your_organization": True, "about_your_organization": self.domain_request.about_your_organization is not None,
"senior_official": self.domain_request.senior_official is not None, "senior_official": self.domain_request.senior_official is not None,
"current_sites": ( "current_sites": (
self.domain_request.current_websites.exists() or self.domain_request.requested_domain is not None self.domain_request.current_websites.exists() or self.domain_request.requested_domain is not None
@ -382,7 +382,11 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
or self.domain_request.no_other_contacts_rationale is not None or self.domain_request.no_other_contacts_rationale is not None
), ),
"additional_details": ( "additional_details": (
(self.domain_request.has_anything_else_text and self.domain_request.has_cisa_representative) # Additional details is complete as long as "has anything else" and "has cisa rep" are not None
(
self.domain_request.has_anything_else_text is not None
and self.domain_request.has_cisa_representative is not None
)
), ),
"requirements": self.domain_request.is_policy_acknowledged is not None, "requirements": self.domain_request.is_policy_acknowledged is not None,
"review": self.domain_request.is_policy_acknowledged is not None, "review": self.domain_request.is_policy_acknowledged is not None,