mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-04 10:13:30 +02:00
refactor testing for joins, remove the no other contacts step
This commit is contained in:
parent
a175018ec7
commit
3783486be7
3 changed files with 13 additions and 21 deletions
|
@ -39,7 +39,6 @@ for step, view in [
|
||||||
(Step.PURPOSE, views.Purpose),
|
(Step.PURPOSE, views.Purpose),
|
||||||
(Step.YOUR_CONTACT, views.YourContact),
|
(Step.YOUR_CONTACT, views.YourContact),
|
||||||
(Step.OTHER_CONTACTS, views.OtherContacts),
|
(Step.OTHER_CONTACTS, views.OtherContacts),
|
||||||
(Step.NO_OTHER_CONTACTS, views.NoOtherContacts),
|
|
||||||
(Step.ANYTHING_ELSE, views.AnythingElse),
|
(Step.ANYTHING_ELSE, views.AnythingElse),
|
||||||
(Step.REQUIREMENTS, views.Requirements),
|
(Step.REQUIREMENTS, views.Requirements),
|
||||||
(Step.REVIEW, views.Review),
|
(Step.REVIEW, views.Review),
|
||||||
|
|
|
@ -96,6 +96,16 @@ class RegistrarFormSet(forms.BaseFormSet):
|
||||||
Hint: Subclass should call `self._to_database(...)`.
|
Hint: Subclass should call `self._to_database(...)`.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def test_if_more_than_one_join(self, db_obj, rel, related_name):
|
||||||
|
|
||||||
|
logger.info(f"rel: {rel} | related_name: {related_name}")
|
||||||
|
|
||||||
|
threshold = 0
|
||||||
|
if rel == related_name:
|
||||||
|
threshold = 1
|
||||||
|
|
||||||
|
return getattr(db_obj, rel) is not None and getattr(db_obj, rel).count() > threshold
|
||||||
|
|
||||||
def _to_database(
|
def _to_database(
|
||||||
self,
|
self,
|
||||||
|
@ -133,17 +143,8 @@ class RegistrarFormSet(forms.BaseFormSet):
|
||||||
logger.info(cleaned)
|
logger.info(cleaned)
|
||||||
# matching database object exists, update it
|
# matching database object exists, update it
|
||||||
if db_obj is not None and cleaned:
|
if db_obj is not None and cleaned:
|
||||||
if should_delete(cleaned):
|
if should_delete(cleaned):
|
||||||
number_of_reverse_joins = 0
|
if any(self.test_if_more_than_one_join(db_obj, rel, related_name) for rel in reverse_joins):
|
||||||
|
|
||||||
for rel in reverse_joins:
|
|
||||||
count = getattr(db_obj, rel).count()
|
|
||||||
logger.info(f"Count for {rel}: {count}")
|
|
||||||
# Increment the counter if the count is greater than 0
|
|
||||||
if count > 0:
|
|
||||||
number_of_reverse_joins += 1
|
|
||||||
|
|
||||||
if any(getattr(db_obj, rel).count() > 1 for rel in reverse_joins) or number_of_reverse_joins > 1:
|
|
||||||
logger.info("Object is joined to something")
|
logger.info("Object is joined to something")
|
||||||
# Remove the specific relationship without deleting the object
|
# Remove the specific relationship without deleting the object
|
||||||
getattr(db_obj, related_name).remove(self.application)
|
getattr(db_obj, related_name).remove(self.application)
|
||||||
|
@ -666,7 +667,7 @@ class OtherContactsForm(RegistrarForm):
|
||||||
|
|
||||||
class BaseOtherContactsFormSet(RegistrarFormSet):
|
class BaseOtherContactsFormSet(RegistrarFormSet):
|
||||||
JOIN = "other_contacts"
|
JOIN = "other_contacts"
|
||||||
REVERSE_JOINS = ["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
|
||||||
|
|
|
@ -42,7 +42,6 @@ class Step(StrEnum):
|
||||||
PURPOSE = "purpose"
|
PURPOSE = "purpose"
|
||||||
YOUR_CONTACT = "your_contact"
|
YOUR_CONTACT = "your_contact"
|
||||||
OTHER_CONTACTS = "other_contacts"
|
OTHER_CONTACTS = "other_contacts"
|
||||||
NO_OTHER_CONTACTS = "no_other_contacts"
|
|
||||||
ANYTHING_ELSE = "anything_else"
|
ANYTHING_ELSE = "anything_else"
|
||||||
REQUIREMENTS = "requirements"
|
REQUIREMENTS = "requirements"
|
||||||
REVIEW = "review"
|
REVIEW = "review"
|
||||||
|
@ -89,7 +88,6 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
|
||||||
Step.PURPOSE: _("Purpose of your domain"),
|
Step.PURPOSE: _("Purpose of your domain"),
|
||||||
Step.YOUR_CONTACT: _("Your contact information"),
|
Step.YOUR_CONTACT: _("Your contact information"),
|
||||||
Step.OTHER_CONTACTS: _("Other employees from your organization"),
|
Step.OTHER_CONTACTS: _("Other employees from your organization"),
|
||||||
Step.NO_OTHER_CONTACTS: _("No other employees from your organization?"),
|
|
||||||
Step.ANYTHING_ELSE: _("Anything else?"),
|
Step.ANYTHING_ELSE: _("Anything else?"),
|
||||||
Step.REQUIREMENTS: _("Requirements for operating .gov domains"),
|
Step.REQUIREMENTS: _("Requirements for operating .gov domains"),
|
||||||
Step.REVIEW: _("Review and submit your domain request"),
|
Step.REVIEW: _("Review and submit your domain request"),
|
||||||
|
@ -102,7 +100,6 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
|
||||||
Step.TRIBAL_GOVERNMENT: lambda w: w.from_model("show_tribal_government", False),
|
Step.TRIBAL_GOVERNMENT: lambda w: w.from_model("show_tribal_government", False),
|
||||||
Step.ORGANIZATION_ELECTION: lambda w: w.from_model("show_organization_election", False),
|
Step.ORGANIZATION_ELECTION: lambda w: w.from_model("show_organization_election", False),
|
||||||
Step.ABOUT_YOUR_ORGANIZATION: lambda w: w.from_model("show_about_your_organization", False),
|
Step.ABOUT_YOUR_ORGANIZATION: lambda w: w.from_model("show_about_your_organization", False),
|
||||||
Step.NO_OTHER_CONTACTS: lambda w: w.from_model("show_no_other_contacts_rationale", False),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -528,11 +525,6 @@ class OtherContacts(ApplicationWizard):
|
||||||
return all_forms_valid
|
return all_forms_valid
|
||||||
|
|
||||||
|
|
||||||
class NoOtherContacts(ApplicationWizard):
|
|
||||||
template_name = "application_no_other_contacts.html"
|
|
||||||
forms = [forms.NoOtherContactsForm]
|
|
||||||
|
|
||||||
|
|
||||||
class AnythingElse(ApplicationWizard):
|
class AnythingElse(ApplicationWizard):
|
||||||
template_name = "application_anything_else.html"
|
template_name = "application_anything_else.html"
|
||||||
forms = [forms.AnythingElseForm]
|
forms = [forms.AnythingElseForm]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue