Gabe Black | 4c040b7 | 2016-11-17 22:35:04 +0000 | [diff] [blame] | 1 | from rest_framework.decorators import api_view |
| 2 | from rest_framework.response import Response |
| 3 | from rest_framework.reverse import reverse |
| 4 | from rest_framework import serializers |
| 5 | from rest_framework import generics |
| 6 | from rest_framework import viewsets |
| 7 | from rest_framework import status |
| 8 | from rest_framework.decorators import detail_route, list_route |
| 9 | from rest_framework.views import APIView |
| 10 | from core.models import * |
| 11 | from django.forms import widgets |
| 12 | from django.conf.urls import patterns, url |
| 13 | from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField |
| 14 | from django.shortcuts import get_object_or_404 |
| 15 | from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied |
| 16 | from xos.exceptions import * |
| 17 | import json |
| 18 | import subprocess |
| 19 | from services.activetest.models import ActiveTestService, VpmaService, Qt600Service |
| 20 | |
| 21 | class ActiveTestSerializer(PlusModelSerializer): |
| 22 | id = ReadOnlyField() |
| 23 | humanReadableName = serializers.SerializerMethodField("getHumanReadableName") |
| 24 | |
| 25 | class Meta: |
| 26 | model = ActiveTestService |
| 27 | fields = ('humanReadableName', |
| 28 | 'id') |
| 29 | |
| 30 | def getHumanReadableName(self, obj): |
| 31 | return obj.__unicode__() |
| 32 | |
| 33 | class ActiveTestViewSet(XOSViewSet): |
| 34 | base_name = "activetest" |
| 35 | method_name = "activetest" |
| 36 | method_kind = "viewset" |
| 37 | queryset = ActiveTestService.get_service_objects().all() |
| 38 | serializer_class = ActiveTestSerializer |
| 39 | |
| 40 | @classmethod |
| 41 | def get_urlpatterns(self, api_path="^"): |
| 42 | patterns = super(ActiveTestViewSet, self).get_urlpatterns(api_path=api_path) |
| 43 | return patterns |
| 44 | |
| 45 | def list(self, request): |
| 46 | object_list = self.filter_queryset(self.get_queryset()) |
| 47 | serializer = self.get_serializer(object_list, many=True) |
| 48 | return Response(serializer.data) |
| 49 | |
| 50 | ############################################################################################ |
| 51 | |
| 52 | class VpmaSerializer(PlusModelSerializer): |
| 53 | id = ReadOnlyField() |
| 54 | humanReadableName = serializers.SerializerMethodField("getHumanReadableName") |
| 55 | |
| 56 | class Meta: |
| 57 | model = VpmaService |
| 58 | fields = ('humanReadableName', |
| 59 | 'id') |
| 60 | |
| 61 | def getHumanReadableName(self, obj): |
| 62 | return obj.__unicode__() |
| 63 | |
| 64 | class VpmaViewSet(XOSViewSet): |
| 65 | base_name = "vpma" |
| 66 | method_name = "vpma" |
| 67 | method_kind = "viewset" |
| 68 | queryset = VpmaService.get_service_objects().all() |
| 69 | serializer_class = VpmaSerializer |
| 70 | |
| 71 | @classmethod |
| 72 | def get_urlpatterns(self, api_path="^"): |
| 73 | patterns = super(VpmaViewSet, self).get_urlpatterns(api_path=api_path) |
| 74 | return patterns |
| 75 | |
| 76 | def list(self, request): |
| 77 | object_list = self.filter_queryset(self.get_queryset()) |
| 78 | serializer = self.get_serializer(object_list, many=True) |
| 79 | return Response(serializer.data) |
| 80 | |
| 81 | class Qt600Serializer(PlusModelSerializer): |
| 82 | id = ReadOnlyField() |
| 83 | humanReadableName = serializers.SerializerMethodField("getHumanReadableName") |
| 84 | |
| 85 | class Meta: |
| 86 | model = Qt600Service |
| 87 | fields = ('humanReadableName', |
| 88 | 'id') |
| 89 | |
| 90 | def getHumanReadableName(self, obj): |
| 91 | return obj.__unicode__() |
| 92 | |
| 93 | class Qt600ViewSet(XOSViewSet): |
| 94 | base_name = "qt600" |
| 95 | method_name = "qt600" |
| 96 | method_kind = "viewset" |
| 97 | queryset = Qt600Service.get_service_objects().all() |
| 98 | serializer_class = Qt600Serializer |
| 99 | |
| 100 | @classmethod |
| 101 | def get_urlpatterns(self, api_path="^"): |
| 102 | patterns = super(Qt600ViewSet, self).get_urlpatterns(api_path=api_path) |
| 103 | return patterns |
| 104 | |
| 105 | def list(self, request): |
| 106 | object_list = self.filter_queryset(self.get_queryset()) |
| 107 | serializer = self.get_serializer(object_list, many=True) |
| 108 | return Response(serializer.data) |