mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-06 01:35:22 +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=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
|
||||
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
|
||||
|
@ -62,15 +62,7 @@ def create_or_update_organization_type(sender, instance, **kwargs):
|
|||
|
||||
# == Init variables == #
|
||||
# Instance is already in the database, fetch its current state
|
||||
if isinstance(instance, DomainRequest):
|
||||
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"
|
||||
)
|
||||
current_instance = sender.objects.get(id=instance.id)
|
||||
|
||||
# Check the new and old values
|
||||
generic_org_type_changed = instance.generic_org_type != current_instance.generic_org_type
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue