| from rest_framework.response import Response |
| from rest_framework import serializers |
| from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField |
| |
| from services.passivetest.models import PassiveTestTenant, PassiveTestService |
| |
| def get_default_passivetest_service(): |
| passivetest_services = PassiveTestService.get_service_objects().all() |
| if passivetest_services: |
| return passivetest_services[0] |
| return None |
| |
| class PassiveTestTenantSerializer(PlusModelSerializer): |
| id = ReadOnlyField() |
| provider_service = serializers.PrimaryKeyRelatedField(queryset=PassiveTestService.get_service_objects().all(), default=get_default_passivetest_service) |
| backend_status = ReadOnlyField() |
| |
| humanReadableName = serializers.SerializerMethodField("getHumanReadableName") |
| |
| class Meta: |
| model = PassiveTestTenant |
| fields = ('humanReadableName', 'id', 'provider_service', 'backend_status') |
| |
| def getHumanReadableName(self, obj): |
| return obj.__unicode__() |
| |
| class PassiveTestTenantViewSet(XOSViewSet): |
| base_name = "passivetesttenant" |
| method_name = "passivetesttenant" |
| method_kind = "viewset" |
| queryset = PassiveTestTenant.get_tenant_objects().all() |
| serializer_class = PassiveTestTenantSerializer |
| |
| |
| def list(self, request): |
| queryset = self.filter_queryset(self.get_queryset()) |
| serializer = self.get_serializer(queryset, many=True) |
| return Response(serializer.data) |
| |