mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-08 13:34:42 +02:00
Code cleanup
This commit is contained in:
parent
46c0d846b6
commit
1fa44a61f1
2 changed files with 27 additions and 27 deletions
|
@ -72,7 +72,6 @@ def check_domain_available(domain):
|
||||||
given domain doesn't end with .gov, ".gov" is added when looking for
|
given domain doesn't end with .gov, ".gov" is added when looking for
|
||||||
a match. If check fails, throws a RegistryError.
|
a match. If check fails, throws a RegistryError.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Domain = apps.get_model("registrar.Domain")
|
Domain = apps.get_model("registrar.Domain")
|
||||||
|
|
||||||
if domain.endswith(".gov"):
|
if domain.endswith(".gov"):
|
||||||
|
|
|
@ -864,13 +864,19 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CisaRepresentativeYesNoForm(RegistrarForm):
|
class BaseYesNoForm(RegistrarForm):
|
||||||
|
"""Used for forms with a yes/no form with a hidden input on toggle"""
|
||||||
|
|
||||||
|
form_is_checked = None
|
||||||
|
typed_choice_field_name = None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Extend the initialization of the form from RegistrarForm __init__"""
|
"""Extend the initialization of the form from RegistrarForm __init__"""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# set the initial value based on attributes of domain request
|
# set the initial value based on attributes of domain request
|
||||||
if self.domain_request:
|
if self.domain_request:
|
||||||
if self.domain_request.has_cisa_representative():
|
if self.form_is_checked:
|
||||||
initial_value = True
|
initial_value = True
|
||||||
else:
|
else:
|
||||||
initial_value = False
|
initial_value = False
|
||||||
|
@ -878,8 +884,8 @@ class CisaRepresentativeYesNoForm(RegistrarForm):
|
||||||
# No pre-selection for new domain requests
|
# No pre-selection for new domain requests
|
||||||
initial_value = None
|
initial_value = None
|
||||||
|
|
||||||
self.fields["has_cisa_representative"] = forms.TypedChoiceField(
|
self.fields[self.typed_choice_field_name] = forms.TypedChoiceField(
|
||||||
coerce=lambda x: x.lower() == "true" if x is not None else None, # coerce strings to bool, excepting None
|
coerce=lambda x: x.lower() == "true" if x is not None else None,
|
||||||
choices=((True, "Yes"), (False, "No")),
|
choices=((True, "Yes"), (False, "No")),
|
||||||
initial=initial_value,
|
initial=initial_value,
|
||||||
widget=forms.RadioSelect,
|
widget=forms.RadioSelect,
|
||||||
|
@ -889,6 +895,16 @@ class CisaRepresentativeYesNoForm(RegistrarForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CisaRepresentativeYesNoForm(BaseYesNoForm):
|
||||||
|
"""Yes/no toggle for the CISA regions question on additional details"""
|
||||||
|
|
||||||
|
# Note that these can be set in __init__ if you need more fine-grained control
|
||||||
|
form_is_checked = property(
|
||||||
|
lambda self: self.domain_request.has_cisa_representative() if self.domain_request else False
|
||||||
|
)
|
||||||
|
typed_choice_field_name = "has_cisa_representative"
|
||||||
|
|
||||||
|
|
||||||
class AdditionalDetailsForm(BaseDeletableRegistrarForm):
|
class AdditionalDetailsForm(BaseDeletableRegistrarForm):
|
||||||
anything_else = forms.CharField(
|
anything_else = forms.CharField(
|
||||||
required=True,
|
required=True,
|
||||||
|
@ -903,29 +919,14 @@ class AdditionalDetailsForm(BaseDeletableRegistrarForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AdditionalDetailsYesNoForm(RegistrarForm):
|
class AdditionalDetailsYesNoForm(BaseYesNoForm):
|
||||||
def __init__(self, *args, **kwargs):
|
"""Yes/no toggle for the anything else question on additional details"""
|
||||||
"""Extend the initialization of the form from RegistrarForm __init__"""
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
# set the initial value based on attributes of domain request
|
|
||||||
if self.domain_request:
|
|
||||||
if self.domain_request.has_anything_else_text():
|
|
||||||
initial_value = True
|
|
||||||
else:
|
|
||||||
initial_value = False
|
|
||||||
else:
|
|
||||||
# No pre-selection for new domain requests
|
|
||||||
initial_value = None
|
|
||||||
|
|
||||||
self.fields["has_anything_else_text"] = forms.TypedChoiceField(
|
# Note that these can be set in __init__ if you need more fine-grained control
|
||||||
coerce=lambda x: x.lower() == "true" if x is not None else None, # coerce strings to bool, excepting None
|
form_is_checked = property(
|
||||||
choices=((True, "Yes"), (False, "No")),
|
lambda self: self.domain_request.has_anything_else_text() if self.domain_request else False
|
||||||
initial=initial_value,
|
)
|
||||||
widget=forms.RadioSelect,
|
typed_choice_field_name = "has_anything_else_text"
|
||||||
error_messages={
|
|
||||||
"required": "This question is required.", # TODO-NL: (design check) - is this required?
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RequirementsForm(RegistrarForm):
|
class RequirementsForm(RegistrarForm):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue