Gabe Black | 9062322 | 2017-01-18 19:52:28 +0000 | [diff] [blame] | 1 | from rest_framework.response import Response |
| 2 | from rest_framework import serializers |
| 3 | from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField |
| 4 | from services.passivetest.models import PassiveTestService |
| 5 | |
| 6 | class 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 | |
| 22 | class 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 | |