mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-03 19:17:42 +02:00
linter
This commit is contained in:
parent
a313c5496b
commit
913f918787
5 changed files with 81 additions and 84 deletions
|
@ -7,6 +7,7 @@ from phonenumber_field.formfields import PhoneNumberField # type: ignore
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.validators import RegexValidator, MaxLengthValidator
|
from django.core.validators import RegexValidator, MaxLengthValidator
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.db.models.fields.related import ForeignObjectRel
|
||||||
|
|
||||||
from api.views import DOMAIN_API_MESSAGES
|
from api.views import DOMAIN_API_MESSAGES
|
||||||
|
|
||||||
|
@ -123,7 +124,14 @@ class RegistrarFormSet(forms.BaseFormSet):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
query = getattr(obj, join).order_by("created_at").all() # order matters
|
query = getattr(obj, join).order_by("created_at").all() # order matters
|
||||||
related_name = obj._meta.get_field(join).related_query_name()
|
|
||||||
|
related_name = ""
|
||||||
|
field = obj._meta.get_field(join)
|
||||||
|
|
||||||
|
if isinstance(field, ForeignObjectRel) and callable(field.related_query_name):
|
||||||
|
related_name = field.related_query_name()
|
||||||
|
elif hasattr(field, "related_query_name") and callable(field.related_query_name):
|
||||||
|
related_name = field.related_query_name()
|
||||||
|
|
||||||
# the use of `zip` pairs the forms in the formset with the
|
# the use of `zip` pairs the forms in the formset with the
|
||||||
# related objects gotten from the database -- there should always be
|
# related objects gotten from the database -- there should always be
|
||||||
|
@ -148,7 +156,7 @@ class RegistrarFormSet(forms.BaseFormSet):
|
||||||
db_obj.save()
|
db_obj.save()
|
||||||
|
|
||||||
# no matching database object, create it
|
# no matching database object, create it
|
||||||
elif db_obj is None and cleaned and not cleaned.get('delete', False):
|
elif db_obj is None and cleaned and not cleaned.get("delete", False):
|
||||||
kwargs = pre_create(db_obj, cleaned)
|
kwargs = pre_create(db_obj, cleaned)
|
||||||
getattr(obj, join).create(**kwargs)
|
getattr(obj, join).create(**kwargs)
|
||||||
|
|
||||||
|
@ -576,14 +584,11 @@ class OtherContactsYesNoForm(RegistrarForm):
|
||||||
# No pre-selection for new applications
|
# No pre-selection for new applications
|
||||||
default_value = None
|
default_value = None
|
||||||
|
|
||||||
self.fields['has_other_contacts'] = forms.TypedChoiceField(
|
self.fields["has_other_contacts"] = forms.TypedChoiceField(
|
||||||
coerce=lambda x: x.lower() == 'true' if x is not None else None,
|
coerce=lambda x: x.lower() == "true" if x is not None else None,
|
||||||
choices=(
|
choices=((True, "Yes, I can name other employees."), (False, "No (We'll ask you to explain why).")),
|
||||||
(True, "Yes, I can name other employees."),
|
|
||||||
(False, "No (We'll ask you to explain why).")
|
|
||||||
),
|
|
||||||
initial=default_value,
|
initial=default_value,
|
||||||
widget=forms.RadioSelect
|
widget=forms.RadioSelect,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -644,14 +649,22 @@ class OtherContactsForm(RegistrarForm):
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
if field in self.errors:
|
if field in self.errors:
|
||||||
del self.errors[field]
|
del self.errors[field]
|
||||||
return {'delete': True}
|
return {"delete": True}
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
|
|
||||||
class BaseOtherContactsFormSet(RegistrarFormSet):
|
class BaseOtherContactsFormSet(RegistrarFormSet):
|
||||||
JOIN = "other_contacts"
|
JOIN = "other_contacts"
|
||||||
REVERSE_JOINS = ["user", "authorizing_official", "submitted_applications", "contact_applications", "information_authorizing_official", "submitted_applications_information", "contact_applications_information"]
|
REVERSE_JOINS = [
|
||||||
|
"user",
|
||||||
|
"authorizing_official",
|
||||||
|
"submitted_applications",
|
||||||
|
"contact_applications",
|
||||||
|
"information_authorizing_official",
|
||||||
|
"submitted_applications_information",
|
||||||
|
"contact_applications_information",
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.formset_data_marked_for_deletion = False
|
self.formset_data_marked_for_deletion = False
|
||||||
|
@ -720,11 +733,7 @@ class NoOtherContactsForm(RegistrarForm):
|
||||||
message="Response must be less than 1000 characters.",
|
message="Response must be less than 1000 characters.",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
error_messages={
|
error_messages={"required": ("Rationale for no other employees is required.")},
|
||||||
"required": (
|
|
||||||
"Rationale for no other employees is required."
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
@ -446,35 +446,23 @@ class TestDomainApplication(TestCase):
|
||||||
"""has_rationale() returns true when an application has no_other_contacts_rationale"""
|
"""has_rationale() returns true when an application has no_other_contacts_rationale"""
|
||||||
self.started_application.no_other_contacts_rationale = "You talkin' to me?"
|
self.started_application.no_other_contacts_rationale = "You talkin' to me?"
|
||||||
self.started_application.save()
|
self.started_application.save()
|
||||||
self.assertEquals(
|
self.assertEquals(self.started_application.has_rationale(), True)
|
||||||
self.started_application.has_rationale(),
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_has_rationale_returns_false(self):
|
def test_has_rationale_returns_false(self):
|
||||||
"""has_rationale() returns false when an application has no no_other_contacts_rationale"""
|
"""has_rationale() returns false when an application has no no_other_contacts_rationale"""
|
||||||
self.assertEquals(
|
self.assertEquals(self.started_application.has_rationale(), False)
|
||||||
self.started_application.has_rationale(),
|
|
||||||
False
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_has_other_contacts_returns_true(self):
|
def test_has_other_contacts_returns_true(self):
|
||||||
"""has_other_contacts() returns true when an application has other_contacts"""
|
"""has_other_contacts() returns true when an application has other_contacts"""
|
||||||
# completed_application has other contacts by default
|
# completed_application has other contacts by default
|
||||||
self.assertEquals(
|
self.assertEquals(self.started_application.has_other_contacts(), True)
|
||||||
self.started_application.has_other_contacts(),
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_has_other_contacts_returns_false(self):
|
def test_has_other_contacts_returns_false(self):
|
||||||
"""has_other_contacts() returns false when an application has no other_contacts"""
|
"""has_other_contacts() returns false when an application has no other_contacts"""
|
||||||
application = completed_application(
|
application = completed_application(
|
||||||
status=DomainApplication.ApplicationStatus.STARTED, name="no-others.gov", has_other_contacts=False
|
status=DomainApplication.ApplicationStatus.STARTED, name="no-others.gov", has_other_contacts=False
|
||||||
)
|
)
|
||||||
self.assertEquals(
|
self.assertEquals(application.has_other_contacts(), False)
|
||||||
application.has_other_contacts(),
|
|
||||||
False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPermissions(TestCase):
|
class TestPermissions(TestCase):
|
||||||
|
|
|
@ -494,7 +494,7 @@ class OtherContacts(ApplicationWizard):
|
||||||
# test first for yes_no_form validity
|
# test first for yes_no_form validity
|
||||||
if other_contacts_yes_no_form.is_valid():
|
if other_contacts_yes_no_form.is_valid():
|
||||||
# test for has_contacts
|
# test for has_contacts
|
||||||
if other_contacts_yes_no_form.cleaned_data.get('has_other_contacts'):
|
if other_contacts_yes_no_form.cleaned_data.get("has_other_contacts"):
|
||||||
# mark the no_other_contacts_form for deletion
|
# mark the no_other_contacts_form for deletion
|
||||||
no_other_contacts_form.mark_form_for_deletion()
|
no_other_contacts_form.mark_form_for_deletion()
|
||||||
# test that the other_contacts_forms and no_other_contacts_forms are valid
|
# test that the other_contacts_forms and no_other_contacts_forms are valid
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue