Project needs to expose all of its ProjectUpdate jobs in an active state

This commit is contained in:
Wayne Witzel III 2018-03-16 08:27:01 -04:00
parent 0689cea806
commit f594f62dfc
2 changed files with 18 additions and 3 deletions

View File

@ -447,6 +447,14 @@ 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 []
class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManagerProjectUpdateMixin, RelatedJobsMixin):
'''
@ -568,10 +576,10 @@ class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManage
'''
def _get_active_jobs(self):
return UnifiedJob.objects.non_polymorphic().filter(
Q(status__in=ACTIVE_STATES) &
models.Q(status__in=ACTIVE_STATES) &
(
Q(Job___project=self) |
Q(ProjectUpdate___project=self)
models.Q(Job___project=self) |
models.Q(ProjectUpdate___project=self)
)
)

View File

@ -251,3 +251,10 @@ def test_project_unique_together_with_org(organization):
proj2.validate_unique()
proj2 = Project(name='foo', organization=None)
proj2.validate_unique()
@pytest.mark.django_db
def test_project_delete(delete, organization, admin):
proj = Project(name='foo', organization=organization)
proj.save()
delete(reverse('api:project_detail', kwargs={'pk':proj.id,}), admin)