diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index 1d51c53641..667efedfba 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -234,7 +234,7 @@ class ProjectOptions(models.Model): return proj_path + '.lock' -class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin, CustomVirtualEnvMixin): +class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin): ''' A project represents a playbook git repo that can access a set of inventories ''' @@ -451,16 +451,21 @@ class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin, CustomVirtualEn def get_absolute_url(self, request=None): return reverse('api:project_detail', kwargs={'pk': self.pk}, request=request) - def get_active_jobs(self): - for project_update in self.project_updates.all(): - active_jobs = project_update.get_active_jobs() - if active_jobs is None: - continue - return active_jobs - return [] + ''' + RelatedJobsMixin + ''' + def _get_active_jobs(self): + return UnifiedJob.objects.non_polymorphic().filter( + models.Q(status__in=ACTIVE_STATES) & + ( + models.Q(Job___project=self) | + models.Q(ProjectUpdate___project=self) + ) + ) -class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManagerProjectUpdateMixin, RelatedJobsMixin): + +class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManagerProjectUpdateMixin): ''' Internal job for tracking project updates from SCM. ''' @@ -575,15 +580,4 @@ class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManage return self.global_instance_groups return selected_groups - ''' - RelatedJobsMixin - ''' - def _get_active_jobs(self): - return UnifiedJob.objects.non_polymorphic().filter( - models.Q(status__in=ACTIVE_STATES) & - ( - models.Q(Job___project=self.project) | - models.Q(ProjectUpdate___project=self.project) - ) - ) diff --git a/awx/main/tests/functional/test_projects.py b/awx/main/tests/functional/test_projects.py index a6cef20f6f..55cc484006 100644 --- a/awx/main/tests/functional/test_projects.py +++ b/awx/main/tests/functional/test_projects.py @@ -254,7 +254,7 @@ def test_project_unique_together_with_org(organization): @pytest.mark.django_db -def test_project_delete(delete, organization, admin): +def test_project_delete(delete, organization, admin_user): proj = Project(name='foo', organization=organization) proj.save() - delete(reverse('api:project_detail', kwargs={'pk':proj.id,}), admin) + delete(reverse('api:project_detail', kwargs={'pk':proj.id,}), admin_user)