mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Move RelatedJob mixin to Project
This commit is contained in:
parent
c628e9de0a
commit
6231742f71
@ -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)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user