Repository: ansible/awx
File: awx/main/models/inventory.py (Python)

Code before:
    JobNotificationMixin
    '''

    def get_notification_templates(self):
        return self.inventory_source.notification_templates

    def get_notification_friendly_name(self):
        return "Inventory Update"

    @property
    def preferred_instance_groups(self):
        if self.inventory_source.inventory is not None and self.inventory_source.inventory.organization is not None:
            organization_groups = [x for x in self.inventory_source.inventory.organization.instance_groups.all()]
        else:
            organization_groups = []
        if self.inventory_source.inventory is not None:
            inventory_groups = [x for x in self.inventory_source.inventory.instance_groups.all()]
        else:
            inventory_groups = []
        selected_groups = inventory_groups + organization_groups
        if not selected_groups:
            return self.global_instance_groups
        return selected_groups

    def cancel(self, job_explanation=None, is_chain=False):
        return super(InventoryUpdate, self).cancel(job_explanation=job_explanation, is_chain=is_chain)


class CustomInventoryScript(CommonModelNameNotUnique, ResourceMixin):
    class Meta:
        app_label = 'main'
        ordering = ('name',)

    script = prevent_search(
        models.TextField(
            blank=True,
            default='',
            help_text=_('Inventory script contents'),
        )
    )

    def get_absolute_url(self, request=None):
        return reverse('api:inventory_script_detail', kwargs={'pk': self.pk}, request=request)


class PluginFileInjector(object):
    plugin_name = None  # Ansible core name used to reference plugin
    # base injector should be one of None, "managed", or "template"
    # this dictates which logic to borrow from playbook injectors
    base_injector = None
    # every source should have collection, these are for the collection name

Review comment (suggestion):
no need to keep this method, you can delete the entire `def` as the super class implementation is fine now.

Code after:
    JobNotificationMixin
    '''

    def get_notification_templates(self):
        return self.inventory_source.notification_templates

    def get_notification_friendly_name(self):
        return "Inventory Update"

    @property
    def preferred_instance_groups(self):
        if self.inventory_source.inventory is not None and self.inventory_source.inventory.organization is not None:
            organization_groups = [x for x in self.inventory_source.inventory.organization.instance_groups.all()]
        else:
            organization_groups = []
        if self.inventory_source.inventory is not None:
            inventory_groups = [x for x in self.inventory_source.inventory.instance_groups.all()]
        else:
            inventory_groups = []
        selected_groups = inventory_groups + organization_groups
        if not selected_groups:
            return self.global_instance_groups
        return selected_groups


class CustomInventoryScript(CommonModelNameNotUnique, ResourceMixin):
    class Meta:
        app_label = 'main'
        ordering = ('name',)

    script = prevent_search(
        models.TextField(
            blank=True,
            default='',
            help_text=_('Inventory script contents'),
        )
    )

    def get_absolute_url(self, request=None):
        return reverse('api:inventory_script_detail', kwargs={'pk': self.pk}, request=request)


class PluginFileInjector(object):
    plugin_name = None  # Ansible core name used to reference plugin
    # base injector should be one of None, "managed", or "template"
    # this dictates which logic to borrow from playbook injectors
    base_injector = None
    # every source should have collection, these are for the collection name
    namespace = None
    collection = None
    collection_migration = '2.9'  # Starting with this version, we use collections