From b331011499db2708683f6ddd0bc0c0fc53c5a6e1 Mon Sep 17 00:00:00 2001 From: Rebecca Hsieh Date: Mon, 7 Oct 2024 14:17:45 -0700 Subject: [PATCH 1/2] Print statements --- src/registrar/admin.py | 10 +++++++- src/registrar/forms/domain.py | 46 ++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index ca51e8b72..7f144665c 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -2464,7 +2464,15 @@ def generic_org_type(self, obj): generic_org_type.admin_order_field = "domain_info__generic_org_type" # type: ignore def federal_agency(self, obj): - return obj.domain_info.federal_agency if obj.domain_info else None + # Print the state of obj and obj.domain_info for troubleshooting + print(f"federal_agency method called for: {obj}") + if obj.domain_info: + print(f"Domain info exists: {obj.domain_info}") + print(f"Federal agency value: {obj.domain_info.federal_agency}") + return obj.domain_info.federal_agency + else: + print("Domain info does not exist") + return None federal_agency.admin_order_field = "domain_info__federal_agency" # type: ignore diff --git a/src/registrar/forms/domain.py b/src/registrar/forms/domain.py index 84fcbe973..502afe9a9 100644 --- a/src/registrar/forms/domain.py +++ b/src/registrar/forms/domain.py @@ -4,7 +4,7 @@ from django import forms from django.core.validators import MinValueValidator, MaxValueValidator, RegexValidator, MaxLengthValidator from django.forms import formset_factory -from registrar.models import DomainRequest +from registrar.models import DomainRequest, FederalAgency from phonenumber_field.widgets import RegionalPhoneNumberWidget from registrar.models.suborganization import Suborganization from registrar.models.utility.domain_helper import DomainHelper @@ -527,19 +527,57 @@ def __init__(self, *args, **kwargs): if field_to_disable is not None: DomainHelper.disable_field(self.fields[field_to_disable], disable_required=True) + # def save(self, commit=True): + # """Override the save() method of the BaseModelForm.""" + # if self.has_changed(): + + # # This action should be blocked by the UI, as the text fields are readonly. + # # If they get past this point, we forbid it this way. + # # This could be malicious, so lets reserve information for the backend only. + # if self.is_federal and not self._field_unchanged("federal_agency"): + # raise ValueError("federal_agency cannot be modified when the generic_org_type is federal") + # elif self.is_tribal and not self._field_unchanged("organization_name"): + # raise ValueError("organization_name cannot be modified when the generic_org_type is tribal") + + # super().save() + def save(self, commit=True): """Override the save() method of the BaseModelForm.""" + + # print("Save method called") if self.has_changed(): + # print("Form has changed") + # print("Generic org type:", self.instance.generic_org_type) + # print("Federal agency:", self.instance.federal_agency) + + # address_fields = [ + # "address_line1", + # "address_line2", + # "city", + # "state_territory", + # "zipcode", + # "urbanization", + # ] + + # if any(field in self.changed_data for field in address_fields): + # print("Address fields have changed") # This action should be blocked by the UI, as the text fields are readonly. # If they get past this point, we forbid it this way. # This could be malicious, so lets reserve information for the backend only. - if self.is_federal and not self._field_unchanged("federal_agency"): - raise ValueError("federal_agency cannot be modified when the generic_org_type is federal") + + if self.is_federal: + if not self._field_unchanged("federal_agency"): + raise ValueError("federal_agency cannot be modified when the generic_org_type is federal") + elif self.is_tribal and not self._field_unchanged("organization_name"): raise ValueError("organization_name cannot be modified when the generic_org_type is tribal") - super().save() + else: # If this error that means Non-Federal Agency is missing + non_federal_agency_instance = FederalAgency.get_non_federal_agency() + self.instance.federal_agency = non_federal_agency_instance + + return super().save(commit=commit) def _field_unchanged(self, field_name) -> bool: """ From 9c4638492bb5b23a68c47ddccbf89786f2f01f78 Mon Sep 17 00:00:00 2001 From: Rebecca Hsieh Date: Mon, 7 Oct 2024 14:19:25 -0700 Subject: [PATCH 2/2] Remove print statements --- src/registrar/admin.py | 5 ----- src/registrar/forms/domain.py | 30 ------------------------------ 2 files changed, 35 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 7f144665c..62ef06c88 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -2464,14 +2464,9 @@ def generic_org_type(self, obj): generic_org_type.admin_order_field = "domain_info__generic_org_type" # type: ignore def federal_agency(self, obj): - # Print the state of obj and obj.domain_info for troubleshooting - print(f"federal_agency method called for: {obj}") if obj.domain_info: - print(f"Domain info exists: {obj.domain_info}") - print(f"Federal agency value: {obj.domain_info.federal_agency}") return obj.domain_info.federal_agency else: - print("Domain info does not exist") return None federal_agency.admin_order_field = "domain_info__federal_agency" # type: ignore diff --git a/src/registrar/forms/domain.py b/src/registrar/forms/domain.py index 502afe9a9..e17e42029 100644 --- a/src/registrar/forms/domain.py +++ b/src/registrar/forms/domain.py @@ -527,40 +527,10 @@ def __init__(self, *args, **kwargs): if field_to_disable is not None: DomainHelper.disable_field(self.fields[field_to_disable], disable_required=True) - # def save(self, commit=True): - # """Override the save() method of the BaseModelForm.""" - # if self.has_changed(): - - # # This action should be blocked by the UI, as the text fields are readonly. - # # If they get past this point, we forbid it this way. - # # This could be malicious, so lets reserve information for the backend only. - # if self.is_federal and not self._field_unchanged("federal_agency"): - # raise ValueError("federal_agency cannot be modified when the generic_org_type is federal") - # elif self.is_tribal and not self._field_unchanged("organization_name"): - # raise ValueError("organization_name cannot be modified when the generic_org_type is tribal") - - # super().save() - def save(self, commit=True): """Override the save() method of the BaseModelForm.""" - # print("Save method called") if self.has_changed(): - # print("Form has changed") - # print("Generic org type:", self.instance.generic_org_type) - # print("Federal agency:", self.instance.federal_agency) - - # address_fields = [ - # "address_line1", - # "address_line2", - # "city", - # "state_territory", - # "zipcode", - # "urbanization", - # ] - - # if any(field in self.changed_data for field in address_fields): - # print("Address fields have changed") # This action should be blocked by the UI, as the text fields are readonly. # If they get past this point, we forbid it this way.