Use sender

This commit is contained in:
zandercymatics 2024-04-02 15:38:12 -06:00
parent 20067eec69
commit 70bd79516a
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -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