From 0bd9919108e636a3d7023abccc039ee900f152cf Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Thu, 5 Apr 2018 11:05:48 -0400 Subject: [PATCH] Make use of callback explicitly for Project and Inventory --- awx/main/signals.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/awx/main/signals.py b/awx/main/signals.py index 64f053eb23..36ad3e21e9 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -250,16 +250,14 @@ def save_related_job_templates(sender, instance, **kwargs): Organization updated. This triggers the rebuilding of the RBAC hierarchy and ensures the proper access restrictions. ''' + if sender not in (Project, Inventory): + raise ValueError('This signal callback is only intended for use with Project or Inventory') + if instance.__original_org != instance.organization: instance.__original_org = instance.organization - jtq = None - if sender == Project: - jtq = JobTemplate.objects.filter(project=instance) - elif sender == Inventory: - jtq = JobTemplate.objects.filter(inventory=instance) - if jtq: - for jt in jtq.all(): - jt.save() + jtq = JobTemplate.objects.filter(**{sender.__name__.lower(): instance}) + for jt in jtq.all(): + jt.save() def connect_computed_field_signals():