mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 02:49:21 +02:00
small refactors
This commit is contained in:
parent
2bc0b28518
commit
7851672dbc
1 changed files with 6 additions and 10 deletions
|
@ -54,19 +54,14 @@ class Contact(TimeStampedModel):
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _get_all_relations(self):
|
||||||
|
return [f.name for f in self._meta.get_fields() if f.is_relation]
|
||||||
|
|
||||||
def has_more_than_one_join(self, expected_relation):
|
def has_more_than_one_join(self, expected_relation):
|
||||||
"""Helper for finding whether an object is joined more than once.
|
"""Helper for finding whether an object is joined more than once.
|
||||||
expected_relation is the one relation with one expected join"""
|
expected_relation is the one relation with one expected join"""
|
||||||
# all_relations is the list of all_relations (from contact) to be checked for existing joins
|
# all_relations is the list of all_relations (from contact) to be checked for existing joins
|
||||||
all_relations = [
|
all_relations = self._get_all_relations()
|
||||||
"user",
|
|
||||||
"authorizing_official",
|
|
||||||
"submitted_applications",
|
|
||||||
"contact_applications",
|
|
||||||
"information_authorizing_official",
|
|
||||||
"submitted_applications_information",
|
|
||||||
"contact_applications_information",
|
|
||||||
]
|
|
||||||
return any(self._has_more_than_one_join_per_relation(rel, expected_relation) for rel in all_relations)
|
return any(self._has_more_than_one_join_per_relation(rel, expected_relation) for rel in all_relations)
|
||||||
|
|
||||||
def _has_more_than_one_join_per_relation(self, relation, expected_relation):
|
def _has_more_than_one_join_per_relation(self, relation, expected_relation):
|
||||||
|
@ -90,7 +85,8 @@ class Contact(TimeStampedModel):
|
||||||
# if the rel field is a OneToOne field, then we have already
|
# if the rel field is a OneToOne field, then we have already
|
||||||
# determined that the object exists (is not None)
|
# determined that the object exists (is not None)
|
||||||
# so return True unless the relation being tested is the expected_relation
|
# so return True unless the relation being tested is the expected_relation
|
||||||
return True if relation != expected_relation else False
|
is_not_expected_relation = relation != expected_relation
|
||||||
|
return is_not_expected_relation
|
||||||
elif isinstance(field, models.ForeignObjectRel):
|
elif isinstance(field, models.ForeignObjectRel):
|
||||||
# if the rel field is a ManyToOne or ManyToMany, then we need
|
# if the rel field is a ManyToOne or ManyToMany, then we need
|
||||||
# to determine if the count of related objects is greater than
|
# to determine if the count of related objects is greater than
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue