Commit 8a0bb0d0 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Let clients fetch only a part of their services

parent 162f2077
from rest_framework import generics
from rest_framework.authentication import TokenAuthentication
from .. import rabbitmq
from . import serializers, models
......@@ -15,14 +14,24 @@ class DeploymentsView(generics.RetrieveAPIView):
serializer_class = serializers.DeploymentsSerializer
def get_object(self):
all = False
all_services = False
if ('all' in self.request.query_params and
self.request.query_params['all'] == 'true'):
all = True
all_services = True
# the client may want only a special selection of services
if 's' in self.request.query_params:
filter_services = self.request.query_params.getlist('s')
print(filter_services)
else:
filter_services = None
d = models.Deployments()
d.services = self.request.user.site.clientapi_get_deployments(all=all)
d.services = self.request.user.site.clientapi_get_deployments(
all=all_services,
filter=filter_services,
)
return d
......
......@@ -70,7 +70,7 @@ class Site(models.Model):
self.last_fetch = make_aware(datetime.now())
self.save()
def clientapi_get_deployments(self, all=False):
def clientapi_get_deployments(self, all=False, filter=None):
def service_deployments(service):
if all:
ds = (
......@@ -92,9 +92,17 @@ class Site(models.Model):
return ds
if filter is not None:
services = [s
for s
in self.services.all()
if s.name in filter]
else:
services = self.services.all()
deployments = {service.name: service_deployments(service)
for service
in self.services.all()}
in services}
# TODO we expect the client to get the update here
self.client_updated()
......
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