Commit d319e3b3 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

manager for active images

parent 098c2b78
Pipeline #15517 failed with stage
in 5 minutes and 19 seconds
......@@ -91,7 +91,7 @@ class Command(BaseCommand):
Image.objects.filter(robotpkg__project__archived=True).delete()
log('\nLook for missing images\n')
for img in Image.objects.filter(created__lt=timezone.now() - timedelta(days=7), target__active=True):
for img in Image.objects.active().filter(created__lt=timezone.now() - timedelta(days=7)):
log(f' {img}')
update_issues_pr()
......
......@@ -5,7 +5,7 @@ from subprocess import check_output
from django.conf import settings
from django.db import models
from django.db.models import Q
from django.db.models import F, Q
from django.db.utils import DataError, IntegrityError
from django.template.loader import get_template
from django.utils import timezone
......@@ -919,7 +919,7 @@ class Robotpkg(NamedModel):
self.save()
def valid_images(self):
return self.image_set.filter(target__active=True, created__isnull=False).order_by('target__name')
return self.image_set.active().filter(created__isnull=False).order_by('target__name')
def without_py(self):
if 'py-' in self.name and self.same_py:
......@@ -932,6 +932,11 @@ class Robotpkg(NamedModel):
# passed = models.BooleanField(default=False)
class ImageQuerySet(models.QuerySet):
def active(self):
return self.filter(Q(target__active=True) | Q(target=F('robotpkg__extended_target')))
class Image(models.Model):
robotpkg = models.ForeignKey(Robotpkg, on_delete=models.CASCADE)
target = models.ForeignKey(Target, on_delete=models.CASCADE)
......@@ -939,6 +944,8 @@ class Image(models.Model):
image = models.CharField(max_length=12, blank=True, null=True)
allow_failure = models.BooleanField(default=False)
objects = ImageQuerySet.as_manager()
class Meta:
unique_together = ('robotpkg', 'target')
......
......@@ -75,7 +75,7 @@ class ProjectImagesView(ProjectTableView):
order_by = 'target'
def get_object_list(self):
return models.Image.objects.filter(robotpkg__project=self.object, target__active=True)
return models.Image.objects.active().filter(robotpkg__project=self.object)
class ProjectContributorsView(ProjectTableView):
......@@ -139,11 +139,7 @@ def docker(request):
filters = request.GET.dict()
if 'cmd' in filters and filters['cmd'] in ['push', 'pull', 'build']:
cmd = filters.pop('cmd')
if 'target__name' in filters and not get_object_or_404(models.Target, name=filters['target__name']).active:
filters['robotpkg__extended_target__name'] = filters['target__name']
else:
filters['target__active'] = True
images = models.Image.objects.filter(**filters)
images = models.Image.objects.active().filter(**filters)
return HttpResponse('\n'.join([' '.join(getattr(image, cmd)()) for image in images]), content_type="text/plain")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment