Commit 70836be3 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add view for the services of a client

parent 924ba8d3
...@@ -32,3 +32,9 @@ class DeploymentsSerializer(serializers.Serializer): ...@@ -32,3 +32,9 @@ class DeploymentsSerializer(serializers.Serializer):
child=DeploymentSerializer() child=DeploymentSerializer()
) )
) )
class ServiceSerializer(serializers.ModelSerializer):
class Meta:
model = models.Service
fields = ['name']
from django.conf.urls import include, url from django.conf.urls import url
from rest_framework import routers # from django.conf.urls import include
# from rest_framework import routers
from . import views from . import views
router = routers.DefaultRouter(trailing_slash=False) # router = routers.DefaultRouter(trailing_slash=False)
# router.register( # router.register(
# r'deployments', views.ClientViewSet, base_name='deployments') # r'deployments', views.ClientViewSet, base_name='deployments')
urlpatterns = [ urlpatterns = [
url(r'^', include(router.urls)), # url(r'^', include(router.urls)),
url(r'^deployments', views.DeploymentsView.as_view()), url(r'^deployments', views.DeploymentsView.as_view()),
url(r'^services', views.ServiceView.as_view()),
] ]
...@@ -4,9 +4,13 @@ from rest_framework.authentication import TokenAuthentication ...@@ -4,9 +4,13 @@ from rest_framework.authentication import TokenAuthentication
from . import serializers, models from . import serializers, models
# authentication class for the client api
authentication_classes = (TokenAuthentication, )
# has an optional url parameter called 'all' which can be set to 'true'
class DeploymentsView(generics.RetrieveAPIView): class DeploymentsView(generics.RetrieveAPIView):
authentication_classes = (TokenAuthentication,) authentication_classes = authentication_classes
serializer_class = serializers.DeploymentsSerializer serializer_class = serializers.DeploymentsSerializer
def get_object(self): def get_object(self):
...@@ -19,3 +23,11 @@ class DeploymentsView(generics.RetrieveAPIView): ...@@ -19,3 +23,11 @@ class DeploymentsView(generics.RetrieveAPIView):
d = models.Deployments() 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)
return d return d
class ServiceView(generics.ListAPIView):
authentication_classes = authentication_classes
serializer_class = serializers.ServiceSerializer
def get_queryset(self):
return self.request.user.site.services.all()
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