blob: f5b556d49729a6c5312316f02a2b9eb1fc97376a [file] [log] [blame]
Gabe Black90623222017-01-18 19:52:28 +00001from rest_framework.response import Response
2from rest_framework import serializers
3from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
4from services.passivetest.models import PassiveTestService
5
6class PassiveTestSerializer(PlusModelSerializer):
7 id = ReadOnlyField()
8 humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
9 tap_ports = serializers.CharField(required=False)
10 reset_viv = serializers.BooleanField(required=False)
11
12 class Meta:
13 model = PassiveTestService
14 fields = ('humanReadableName',
15 'id',
16 'tap_ports',
17 'reset_viv')
18
19 def getHumanReadableName(self, obj):
20 return obj.__unicode__()
21
22class PassiveTestViewSet(XOSViewSet):
23 base_name = "passivetest"
24 method_name = "passivetest"
25 method_kind = "viewset"
26 queryset = PassiveTestService.get_service_objects().all()
27 serializer_class = PassiveTestSerializer
28
29 @classmethod
30 def get_urlpatterns(self, api_path="^"):
31 patterns = super(PassiveTestViewSet, self).get_urlpatterns(api_path=api_path)
32 return patterns
33
34 def list(self, request):
35 object_list = self.filter_queryset(self.get_queryset())
36 serializer = self.get_serializer(object_list, many=True)
37 return Response(serializer.data)
38