mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 14:04:10 +02:00
Use sender
This commit is contained in:
parent
20067eec69
commit
70bd79516a
1 changed files with 2 additions and 10 deletions
|
@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@receiver(pre_save, sender=DomainRequest)
|
@receiver(pre_save, sender=DomainRequest)
|
||||||
@receiver(pre_save, sender=DomainInformation)
|
@receiver(pre_save, sender=DomainInformation)
|
||||||
def create_or_update_organization_type(sender, instance, **kwargs):
|
def create_or_update_organization_type(sender: DomainRequest | DomainInformation, instance, **kwargs):
|
||||||
"""The organization_type field on DomainRequest and DomainInformation is consituted from the
|
"""The organization_type field on DomainRequest and DomainInformation is consituted from the
|
||||||
generic_org_type and is_election_board fields. To keep the organization_type
|
generic_org_type and is_election_board fields. To keep the organization_type
|
||||||
field up to date, we need to update it before save based off of those field
|
field up to date, we need to update it before save based off of those field
|
||||||
|
@ -62,15 +62,7 @@ def create_or_update_organization_type(sender, instance, **kwargs):
|
||||||
|
|
||||||
# == Init variables == #
|
# == Init variables == #
|
||||||
# Instance is already in the database, fetch its current state
|
# Instance is already in the database, fetch its current state
|
||||||
if isinstance(instance, DomainRequest):
|
current_instance = sender.objects.get(id=instance.id)
|
||||||
current_instance = DomainRequest.objects.get(id=instance.id)
|
|
||||||
elif isinstance(instance, DomainInformation):
|
|
||||||
current_instance = DomainInformation.objects.get(id=instance.id)
|
|
||||||
else:
|
|
||||||
# This should never occur. But it never hurts to have this check anyway.
|
|
||||||
raise ValueError(
|
|
||||||
"create_or_update_organization_type() -> instance was not DomainRequest or DomainInformation"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check the new and old values
|
# Check the new and old values
|
||||||
generic_org_type_changed = instance.generic_org_type != current_instance.generic_org_type
|
generic_org_type_changed = instance.generic_org_type != current_instance.generic_org_type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue