mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-30 06:26:34 +02:00
clean up of requesting entity
This commit is contained in:
parent
6a49f9e373
commit
088140a37d
2 changed files with 2 additions and 79 deletions
|
@ -116,44 +116,18 @@ class RequestingEntityForm(RegistrarForm):
|
|||
)
|
||||
return name
|
||||
|
||||
# def full_clean(self):
|
||||
# """Validation logic to remove the custom suborganization value before clean is triggered.
|
||||
# Without this override, the form will throw an 'invalid option' error."""
|
||||
# # Remove the custom other field before cleaning
|
||||
# data = self.data.copy() if self.data else None
|
||||
|
||||
# # Remove the 'other' value from suborganization if it exists.
|
||||
# # This is a special value that tracks if the user is requesting a new suborg.
|
||||
# suborganization = self.data.get("portfolio_requesting_entity-sub_organization")
|
||||
# if suborganization and "other" in suborganization:
|
||||
# data["portfolio_requesting_entity-sub_organization"] = ""
|
||||
|
||||
# # Set the modified data back to the form
|
||||
# self.data = data
|
||||
|
||||
# # Call the parent's full_clean method
|
||||
# super().full_clean()
|
||||
|
||||
def full_clean(self):
|
||||
"""Validation logic to temporarily remove the custom suborganization value before clean is triggered.
|
||||
Without this override, the form will throw an 'invalid option' error."""
|
||||
logger.debug("full_clean")
|
||||
# Ensure self.data is not None before proceeding
|
||||
if self.data:
|
||||
# handle case where form has been submitted
|
||||
logger.debug("form was submitted")
|
||||
# Create a copy of the data for manipulation
|
||||
data = self.data.copy()
|
||||
|
||||
# Retrieve sub_organization
|
||||
# Retrieve sub_organization and store in _original_suborganization
|
||||
suborganization = data.get("portfolio_requesting_entity-sub_organization")
|
||||
|
||||
logger.debug(f"suborganization submitted as {suborganization}")
|
||||
# # Determine if "other" should be stored in _original_suborganization
|
||||
# if not suborganization:
|
||||
# logger.debug("suborg stored as other")
|
||||
# self._original_suborganization = "other"
|
||||
# else:
|
||||
self._original_suborganization = suborganization
|
||||
|
||||
# If the original value was "other", clear it for validation
|
||||
|
@ -166,69 +140,27 @@ class RequestingEntityForm(RegistrarForm):
|
|||
# handle case of a GET
|
||||
suborganization = None
|
||||
if self.initial and "sub_organization" in self.initial:
|
||||
print("suborg in self.initial")
|
||||
suborganization = self.initial["sub_organization"]
|
||||
print(self.initial["sub_organization"])
|
||||
print(suborganization)
|
||||
|
||||
# Check if is_requesting_new_suborganization is True
|
||||
is_requesting_new_suborganization = False
|
||||
if self.initial and "is_requesting_new_suborganization" in self.initial:
|
||||
# Call the method if it exists
|
||||
print(self.initial["is_requesting_new_suborganization"]())
|
||||
is_requesting_new_suborganization = self.initial["is_requesting_new_suborganization"]()
|
||||
|
||||
# Determine if "other" should be set
|
||||
if is_requesting_new_suborganization and suborganization is None:
|
||||
print("presetting to other")
|
||||
self._original_suborganization = "other"
|
||||
else:
|
||||
self._original_suborganization = suborganization
|
||||
print("self.data does not exist")
|
||||
print(self.initial)
|
||||
# # Handle the initial GET request case
|
||||
# self._original_suborganization = None
|
||||
|
||||
# Call the parent's full_clean method
|
||||
super().full_clean()
|
||||
|
||||
# Restore "other" if there are errors
|
||||
if self.errors:
|
||||
logger.debug(f"errors detected: {self.errors}; resetting original_sub_organization")
|
||||
self.data["portfolio_requesting_entity-sub_organization"] = self._original_suborganization
|
||||
|
||||
|
||||
# def clean(self):
|
||||
# """Custom clean implementation to handle our desired logic flow for suborganization.
|
||||
# Given that these fields often rely on eachother, we need to do this in the parent function."""
|
||||
# cleaned_data = super().clean()
|
||||
|
||||
# # Do some custom error validation if the requesting entity is a suborg.
|
||||
# # Otherwise, just validate as normal.
|
||||
# suborganization = self.cleaned_data.get("sub_organization")
|
||||
# is_requesting_new_suborganization = self.cleaned_data.get("is_requesting_new_suborganization")
|
||||
|
||||
# # Get the value of the yes/no checkbox from RequestingEntityYesNoForm.
|
||||
# # Since self.data stores this as a string, we need to convert "True" => True.
|
||||
# requesting_entity_is_suborganization = self.data.get(
|
||||
# "portfolio_requesting_entity-requesting_entity_is_suborganization"
|
||||
# )
|
||||
# if requesting_entity_is_suborganization == "True":
|
||||
# if is_requesting_new_suborganization:
|
||||
# # Validate custom suborganization fields
|
||||
# if not cleaned_data.get("requested_suborganization") and "requested_suborganization" not in self.errors:
|
||||
# self.add_error("requested_suborganization", "Enter the name of your suborganization.")
|
||||
# if not cleaned_data.get("suborganization_city"):
|
||||
# self.add_error("suborganization_city", "Enter the city where your suborganization is located.")
|
||||
# if not cleaned_data.get("suborganization_state_territory"):
|
||||
# self.add_error(
|
||||
# "suborganization_state_territory",
|
||||
# "Select the state, territory, or military post where your suborganization is located.",
|
||||
# )
|
||||
# elif not suborganization:
|
||||
# self.add_error("sub_organization", "Suborganization is required.")
|
||||
|
||||
# return cleaned_data
|
||||
|
||||
def clean(self):
|
||||
"""Custom clean implementation to handle our desired logic flow for suborganization."""
|
||||
cleaned_data = super().clean()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue