tenant api for VTR and ExampleService
diff --git a/xos/api/tenant/exampletenant.py b/xos/api/tenant/exampletenant.py
new file mode 100644
index 0000000..b046a88
--- /dev/null
+++ b/xos/api/tenant/exampletenant.py
@@ -0,0 +1,55 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import serializers
+from rest_framework import generics
+from rest_framework import status
+from core.models import *
+from django.forms import widgets
+from services.cord.models import CordSubscriberRoot
+from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
+from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
+
+from services.exampleservice.models import ExampleTenant, ExampleService
+
+def get_default_example_service():
+ example_services = ExampleService.get_service_objects().all()
+ if example_services:
+ return example_services[0]
+ return None
+
+class ExampleTenantSerializer(PlusModelSerializer):
+ id = ReadOnlyField()
+ provider_service = serializers.PrimaryKeyRelatedField(queryset=ExampleService.get_service_objects().all(), default=get_default_example_service)
+ tenant_message = serializers.CharField(required=False)
+ backend_status = ReadOnlyField()
+
+ humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+
+ class Meta:
+ model = ExampleTenant
+ fields = ('humanReadableName', 'id', 'provider_service', 'tenant_message', 'backend_status')
+
+ def getHumanReadableName(self, obj):
+ return obj.__unicode__()
+
+class ExampleTenantViewSet(XOSViewSet):
+ base_name = "exampletenant"
+ method_name = "exampletenant"
+ method_kind = "viewset"
+ queryset = ExampleTenant.get_tenant_objects().all()
+ serializer_class = ExampleTenantSerializer
+
+ @classmethod
+ def get_urlpatterns(self, api_path="^"):
+ patterns = super(ExampleTenantViewSet, self).get_urlpatterns(api_path=api_path)
+
+ return patterns
+
+ def list(self, request):
+ queryset = self.filter_queryset(self.get_queryset())
+
+ serializer = self.get_serializer(queryset, many=True)
+
+ return Response(serializer.data)
+
diff --git a/xos/api/tenant/truckroll.py b/xos/api/tenant/truckroll.py
new file mode 100644
index 0000000..ea0200d
--- /dev/null
+++ b/xos/api/tenant/truckroll.py
@@ -0,0 +1,68 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import serializers
+from rest_framework import generics
+from rest_framework import status
+from core.models import *
+from django.forms import widgets
+from services.cord.models import CordSubscriberRoot
+from services.vtr.models import VTRTenant, VTRService
+from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
+from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
+
+def get_default_vtr_service():
+ vtr_services = VTRService.get_service_objects().all()
+ if vtr_services:
+ return vtr_services[0].id
+ return None
+
+class VTRTenantForAPI(VTRTenant):
+ class Meta:
+ proxy = True
+ app_label = "cord"
+
+class VTRTenantSerializer(PlusModelSerializer):
+ id = ReadOnlyField()
+ target_id = serializers.IntegerField()
+ test = serializers.CharField()
+ scope = serializers.CharField()
+ argument = serializers.CharField(required=False)
+ provider_service = serializers.PrimaryKeyRelatedField(queryset=VTRService.get_service_objects().all(), default=get_default_vtr_service)
+ result = serializers.CharField(required=False)
+ result_code = serializers.CharField(required=False)
+ backend_status = ReadOnlyField()
+
+ humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+ is_synced = serializers.SerializerMethodField("isSynced")
+
+ class Meta:
+ model = VTRTenantForAPI
+ fields = ('humanReadableName', 'id', 'provider_service', 'target_id', 'scope', 'test', 'argument', 'result', 'result_code', 'is_synced', 'backend_status' )
+
+ def getHumanReadableName(self, obj):
+ return obj.__unicode__()
+
+ def isSynced(self, obj):
+ return (obj.enacted is not None) and (obj.enacted >= obj.updated)
+
+class TruckRollViewSet(XOSViewSet):
+ base_name = "truckroll"
+ method_name = "truckroll"
+ method_kind = "viewset"
+ queryset = VTRTenantForAPI.get_tenant_objects().all() # select_related().all()
+ serializer_class = VTRTenantSerializer
+
+ @classmethod
+ def get_urlpatterns(self, api_path="^"):
+ patterns = super(TruckRollViewSet, self).get_urlpatterns(api_path=api_path)
+
+ return patterns
+
+ def list(self, request):
+ queryset = self.filter_queryset(self.get_queryset())
+
+ serializer = self.get_serializer(queryset, many=True)
+
+ return Response(serializer.data)
+