Commit 2d9d1701 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Clientapi fetches now only previously unfetched deployments

parent a826af4f
......@@ -10,6 +10,12 @@ class DeploymentsView(generics.RetrieveAPIView):
serializer_class = serializers.DeploymentsSerializer
def get_object(self):
all = False
if ('all' in self.request.query_params and
self.request.query_params['all'] == 'true'):
all = True
d = models.Deployments()
d.services = self.request.user.site.clientapi_get_deployments()
d.services = self.request.user.site.clientapi_get_deployments(all=all)
return d
......@@ -53,16 +53,21 @@ class Site(models.Model):
def __str__(self):
return self.name
def clientapi_get_deployments(self):
def clientapi_get_deployments(self, all=False):
services = {}
for service in self.services.all():
# deployments with ssh keys
services[service.name] = (
ds = (
service.deployments
.filter(user__user_type='oidcuser')
.exclude(ssh_keys=None)
)
if not all:
ds = ds.filter(last_change__gt=self.last_fetch)
# deployments with ssh keys
services[service.name] = ds
self.last_fetch = datetime.now()
self.save()
return services
......@@ -111,6 +116,9 @@ class Deployment(models.Model):
related_name='deployments',
blank=True,
)
last_change = models.DateTimeField(
auto_now=True
)
def __str__(self):
return str(self.user) + '@' + str(self.service)
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